Skip to content

Commit

Permalink
Add support for large number of stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Katafalkas committed Aug 17, 2019
1 parent a210f2d commit f1a8a66
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
29 changes: 20 additions & 9 deletions index.ts
Expand Up @@ -554,15 +554,26 @@ class ServerlessCustomDomain {
}
const stackFamilyName = this.serverless.service.provider.stackName ||
`${this.serverless.service.service}-${this.stage}`;
let familyStackNames;
try {
const describeStacksResponse = await this.cloudformation.describeStacks().promise();
familyStackNames = describeStacksResponse.Stacks
.map((stack) => stack.StackName)
.filter((stackName) => stackName.includes(stackFamilyName));
} catch (err) {
throw new Error("Error: Retrieving CloudFormation stacks.\n");
}
const allStackDescriptions = [];
let nextToken = true;
while (nextToken) {
try {
const params = { NextToken: undefined };
if (typeof nextToken === "string") {
params.NextToken = nextToken;
}
const describeStacksResponse = await this.cloudformation.describeStacks(params).promise();
for (const stackDescription of describeStacksResponse.Stacks) {
allStackDescriptions.push(stackDescription);
}
nextToken = describeStacksResponse.NextToken;
} catch (err) {
throw new Error("Error: Retrieving CloudFormation stacks.\n");
}
}
const familyStackNames = allStackDescriptions
.map((stack) => stack.StackName)
.filter((stackName) => stackName.includes(stackFamilyName));
let response;
for (const familyStackName of familyStackNames) {
try {
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "3.3.0",
"version": "3.3.1",
"engines": {
"node": ">=4.0"
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/index.test.ts
Expand Up @@ -460,7 +460,7 @@ describe("Custom Domain Plugin", () => {

describe("Gets Rest API correctly", () => {
it("Fetches restApiId correctly when no ApiGateway specified", async () => {
AWS.mock("CloudFormation", "describeStacks", (callback) => {
AWS.mock("CloudFormation", "describeStacks", (params, callback) => {
callback(null, {
Stacks: [
{
Expand Down Expand Up @@ -634,7 +634,7 @@ describe("Custom Domain Plugin", () => {
AWS.mock("APIGateway", "createBasePathMapping", (params, callback) => {
callback(null, params);
});
AWS.mock("CloudFormation", "describeStacks", (callback) => {
AWS.mock("CloudFormation", "describeStacks", (params, callback) => {
callback(null, {
Stacks: [
{
Expand Down

0 comments on commit f1a8a66

Please sign in to comment.