From 0dd34dd85379abaee23c23caa3e8e4565b64087c Mon Sep 17 00:00:00 2001 From: Reagan Elm <1347066+relm923@users.noreply.github.com> Date: Wed, 10 Aug 2022 08:33:11 -0400 Subject: [PATCH] feat(cli): --concurrency option (#20345) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1973 (reattempting #19378) Add `--concurrency` parameter to `cdk deploy` command to enable concurrent deployments while respecting stack dependencies. Concurrency mode will only work with `--progress events` due to the poor interaction of concurrent deployments and the progress bar rendering. ### Open Questions - [x] How best to write automated tests around this? Added unit and integration tests - [x] Should other commands (ex: `destroy`) support concurrency? Only supporting deploy command in this PR - [x] Any other concerns with this approach as it changes a key component of `cdk` - [x] How should this work with the `--exclusively` flag? Only check dependencies between requested stacks
Example Output (Success):
$ yarn cdk deploy --all --require-approval "never" --concurrency 3 --progress bar
yarn run v1.22.17
warning package.json: No license field
$ cdk deploy --all --require-approval never --concurrency 3 --progress bar

✨  Synthesis time: 16.04s

⚠️ The --concurrency flag only supports --progress "events". Switching to "events".
relm-test-1
relm-test-1: deploying...
relm-test-2: deploying...
relm-test-2: creating CloudFormation changeset...
relm-test-1: creating CloudFormation changeset...
relm-test-1 | 0/3 | 4:57:19 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-1 User Initiated
relm-test-1 | 0/3 | 4:57:24 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-1 User Initiated
relm-test-1 | 0/3 | 4:57:30 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C)
relm-test-2 | 0/3 | 4:57:19 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-2 User Initiated
relm-test-2 | 0/3 | 4:57:24 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-2 User Initiated
relm-test-2 | 0/3 | 4:57:29 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C)
relm-test-2 | 0/3 | 4:57:29 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-1 | 0/3 | 4:57:30 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-1 | 0/3 | 4:57:30 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C) Resource creation Initiated
relm-test-1 | 0/3 | 4:57:32 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation Initiated
relm-test-1 | 1/3 | 4:57:33 PM | CREATE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-2 | 0/3 | 4:57:30 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C) Resource creation Initiated
relm-test-2 | 0/3 | 4:57:31 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation Initiated
relm-test-2 | 1/3 | 4:57:32 PM | CREATE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-2 | 2/3 | 4:57:41 PM | CREATE_COMPLETE      | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C)
relm-test-2 | 3/3 | 4:57:43 PM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | relm-test-2
relm-test-1 | 2/3 | 4:57:41 PM | CREATE_COMPLETE      | AWS::SNS::Topic    | TempTopic (TempTopic9C0CBD7C)
relm-test-1 | 3/3 | 4:57:43 PM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | relm-test-1

✅  relm-test-1

✨  Deployment time: 28.39s

Stack ARN:
arn:aws:cloudformation:us-east-1:XXXXXXXXXXXX:stack/relm-test-1/ffcdb210-a6fd-11ec-b05c-0a02909bf4fb

✨  Total time: 44.43s


✅  relm-test-2

✨  Deployment time: 28.45s

Outputs:
relm-test-2.ExportsOutputRefTempTopic9C0CBD7CC97C6BE5 = arn:aws:sns:us-east-1:XXXXXXXXXXXX:relm-test-2-TempTopic9C0CBD7C-2ETJWELY3MFD
Stack ARN:
arn:aws:cloudformation:us-east-1:XXXXXXXXXXXX:stack/relm-test-2/ffbc7400-a6fd-11ec-ac95-0ea201c9d581

✨  Total time: 44.49s

relm-test-2B
relm-test-2B: deploying...
relm-test-2B: creating CloudFormation changeset...
relm-test-2B | 0/4 | 4:57:47 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-2B User Initiated
relm-test-2B | 0/4 | 4:57:58 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-2B User Initiated
relm-test-2B | 0/4 | 4:58:04 PM | CREATE_IN_PROGRESS   | AWS::IAM::Role     | TopicRole (TopicRole3526982D)
relm-test-2B | 0/4 | 4:58:04 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-2B | 0/4 | 4:58:05 PM | CREATE_IN_PROGRESS   | AWS::IAM::Role     | TopicRole (TopicRole3526982D) Resource creation Initiated
relm-test-2B | 0/4 | 4:58:06 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation Initiated
relm-test-2B | 1/4 | 4:58:07 PM | CREATE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-2B | 2/4 | 4:58:19 PM | CREATE_COMPLETE      | AWS::IAM::Role     | TopicRole (TopicRole3526982D)
relm-test-2B | 2/4 | 4:58:22 PM | CREATE_IN_PROGRESS   | AWS::IAM::Policy   | TopicRole/DefaultPolicy (TopicRoleDefaultPolicy489E2B68)
relm-test-2B | 2/4 | 4:58:23 PM | CREATE_IN_PROGRESS   | AWS::IAM::Policy   | TopicRole/DefaultPolicy (TopicRoleDefaultPolicy489E2B68) Resource creation Initiated
relm-test-2B | 3/4 | 4:58:36 PM | CREATE_COMPLETE      | AWS::IAM::Policy   | TopicRole/DefaultPolicy (TopicRoleDefaultPolicy489E2B68)
relm-test-2B | 4/4 | 4:58:37 PM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | relm-test-2B

✅  relm-test-2B

✨  Deployment time: 54.71s

Stack ARN:
arn:aws:cloudformation:us-east-1:XXXXXXXXXXXX:stack/relm-test-2B/10b341d0-a6fe-11ec-a535-12d49b16bf9b

✨  Total time: 70.75s


✨  Done in 99.79s.
  
Example Output (Failure):
yarn run v1.22.18
warning package.json: No license field
$ cdk deploy --all --require-approval never --concurrency 3 --progress bar

✨  Synthesis time: 16.18s

⚠️ The --concurrency flag only supports --progress "events". Switching to "events".
relm-broken-1
relm-broken-1: deploying...
relm-broken-2
relm-broken-2: deploying...
relm-test-1: deploying...
relm-test-1: creating CloudFormation changeset...
relm-broken-1: creating CloudFormation changeset...
relm-broken-2: creating CloudFormation changeset...
relm-broken-2 | 0/3 | 9:12:48 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-broken-2 User Initiated
relm-broken-2 | 0/3 | 9:12:53 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-broken-2 User Initiated
relm-broken-1 | 0/3 | 9:12:48 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-broken-1 User Initiated
relm-broken-1 | 0/3 | 9:12:53 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-broken-1 User Initiated
relm-test-1 | 0/3 | 9:12:48 PM | REVIEW_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-1 User Initiated
relm-test-1 | 0/3 | 9:12:54 PM | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack | relm-test-1 User Initiated
relm-test-1 | 0/3 | 9:12:59 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)
relm-test-1 | 0/3 | 9:12:59 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-test-1 | 0/3 | 9:13:00 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TestTopic (TestTopic339EC197) Resource creation Initiated
relm-test-1 | 0/3 | 9:13:01 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation Initiated
relm-test-1 | 1/3 | 9:13:02 PM | CREATE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-broken-2 | 0/3 | 9:12:59 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)
relm-broken-2 | 0/3 | 9:12:59 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-broken-2 | 0/3 | 9:13:00 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TestTopic (TestTopic339EC197) Resource creation Initiated
relm-broken-2 | 0/3 | 9:13:02 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation Initiated
relm-broken-2 | 1/3 | 9:13:02 PM | CREATE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-broken-1 | 0/3 | 9:13:04 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-broken-1 | 0/3 | 9:13:04 PM | CREATE_IN_PROGRESS   | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)
relm-broken-1 | 0/3 | 9:13:04 PM | CREATE_FAILED        | AWS::SNS::Topic    | TestTopic (TestTopic339EC197) TestTopic already exists in stack arn:aws:cloudformation:us-east-1:__ACCOUNT_ID__:stack/relm-broken-2/79fc1770-cc10-11ec-8279-0a02b75d1237
        new Topic (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/aws-sns/lib/topic.ts:102:22)
        \_ new BrokenStack (/Users/relm/Development/aws-cdk-test-stack/lib/broken-stack.ts:11:18)
        \_ Object. (/Users/relm/Development/aws-cdk-test-stack/bin/aws-cdk-test-stack.ts:12:1)
        \_ Module._compile (node:internal/modules/cjs/loader:1103:14)
        \_ Module.m._compile (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/index.ts:1455:23)
        \_ Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
        \_ Object.require.extensions. [as .ts] (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/index.ts:1458:12)
        \_ Module.load (node:internal/modules/cjs/loader:981:32)
        \_ Function.Module._load (node:internal/modules/cjs/loader:822:12)
        \_ Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
        \_ phase4 (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:567:12)
        \_ bootstrap (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:85:10)
        \_ main (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:54:10)
        \_ Object. (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:717:3)
        \_ Module._compile (node:internal/modules/cjs/loader:1103:14)
        \_ Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
        \_ Module.load (node:internal/modules/cjs/loader:981:32)
        \_ Function.Module._load (node:internal/modules/cjs/loader:822:12)
        \_ Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
        \_ node:internal/main/run_main_module:17:47
relm-broken-1 | 0/3 | 9:13:05 PM | CREATE_FAILED        | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata) Resource creation cancelled
        new MetadataResource (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/metadata-resource.ts:22:24)
        \_ /Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/synthesis.ts:166:5
        \_ visit (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/synthesis.ts:231:5)
        \_ visit (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/synthesis.ts:227:5)
        \_ injectMetadataResources (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/synthesis.ts:157:3)
        \_ Object.synthesize (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/private/synthesis.ts:18:3)
        \_ App.synth (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/stage.ts:180:23)
        \_ process. (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/core/lib/app.ts:131:45)
        \_ Object.onceWrapper (node:events:646:26)
        \_ process.emit (node:events:526:28)
        \_ process.emit (node:domain:475:12)
        \_ process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/relm/Development/aws-cdk-test-stack/node_modules/@cspotcode/source-map-support/source-map-support.js:613:40)
relm-broken-1 | 0/3 | 9:13:06 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | relm-broken-1 The following resource(s) failed to create: [TestTopic339EC197, CDKMetadata]. Rollback requested by user.
relm-broken-1 | 1/3 | 9:13:10 PM | DELETE_COMPLETE      | AWS::CDK::Metadata | CDKMetadata/Default (CDKMetadata)
relm-broken-1 | 2/3 | 9:13:10 PM | DELETE_COMPLETE      | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)
relm-broken-1 | 3/3 | 9:13:11 PM | ROLLBACK_COMPLETE    | AWS::CloudFormation::Stack | relm-broken-1
relm-broken-2 | 2/3 | 9:13:11 PM | CREATE_COMPLETE      | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)
relm-broken-2 | 3/3 | 9:13:12 PM | CREATE_COMPLETE      | AWS::CloudFormation::Stack | relm-broken-2
relm-test-1 | 2/3 | 9:13:10 PM | CREATE_COMPLETE      | AWS::SNS::Topic    | TestTopic (TestTopic339EC197)

Failed resources:
relm-broken-1 | 9:13:04 PM | CREATE_FAILED        | AWS::SNS::Topic    | TestTopic (TestTopic339EC197) TestTopic already exists in stack arn:aws:cloudformation:us-east-1:__ACCOUNT_ID__:stack/relm-broken-2/79fc1770-cc10-11ec-8279-0a02b75d1237
        new Topic (/Users/relm/Development/aws-cdk/packages/aws-cdk-lib/aws-sns/lib/topic.ts:102:22)
        \_ new BrokenStack (/Users/relm/Development/aws-cdk-test-stack/lib/broken-stack.ts:11:18)
        \_ Object. (/Users/relm/Development/aws-cdk-test-stack/bin/aws-cdk-test-stack.ts:12:1)
        \_ Module._compile (node:internal/modules/cjs/loader:1103:14)
        \_ Module.m._compile (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/index.ts:1455:23)
        \_ Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
        \_ Object.require.extensions. [as .ts] (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/index.ts:1458:12)
        \_ Module.load (node:internal/modules/cjs/loader:981:32)
        \_ Function.Module._load (node:internal/modules/cjs/loader:822:12)
        \_ Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
        \_ phase4 (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:567:12)
        \_ bootstrap (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:85:10)
        \_ main (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:54:10)
        \_ Object. (/Users/relm/Development/aws-cdk-test-stack/node_modules/ts-node/src/bin.ts:717:3)
        \_ Module._compile (node:internal/modules/cjs/loader:1103:14)
        \_ Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
        \_ Module.load (node:internal/modules/cjs/loader:981:32)
        \_ Function.Module._load (node:internal/modules/cjs/loader:822:12)
        \_ Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
        \_ node:internal/main/run_main_module:17:47

❌  relm-broken-1 failed: Error: The stack named relm-broken-1 failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts:307:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at prepareAndExecuteChangeSet (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/api/deploy-stack.ts:355:26)
    at deployStack (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts:229:24)
    at /Users/relm/Development/aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts:306:13
    at run (/Users/relm/Development/aws-cdk/node_modules/p-queue/dist/index.js:163:29)

/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts:307
    throw new Error(`The stack named ${stackName} failed creation, it may need to be manually deleted from the AWS console: ${status}`);
          ^
Error: The stack named relm-broken-1 failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/api/util/cloudformation.ts:307:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at prepareAndExecuteChangeSet (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/api/deploy-stack.ts:355:26)
    at deployStack (/Users/relm/Development/aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts:229:24)
    at /Users/relm/Development/aws-cdk/packages/aws-cdk/lib/cdk-toolkit.ts:306:13
    at run (/Users/relm/Development/aws-cdk/node_modules/p-queue/dist/index.js:163:29)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  
---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk/README.md | 2 + packages/aws-cdk/THIRD_PARTY_LICENSES | 80 ++++++++ packages/aws-cdk/lib/cdk-toolkit.ts | 41 +++- packages/aws-cdk/lib/cli.ts | 4 +- packages/aws-cdk/lib/deploy.ts | 60 ++++++ packages/aws-cdk/package.json | 1 + packages/aws-cdk/test/deploy.test.ts | 187 ++++++++++++++++++ .../aws-cdk/test/integ/cli/cli.integtest.ts | 20 +- packages/aws-cdk/tsconfig.json | 4 +- 9 files changed, 390 insertions(+), 9 deletions(-) create mode 100644 packages/aws-cdk/lib/deploy.ts create mode 100644 packages/aws-cdk/test/deploy.test.ts diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 4fe06d1878abf..09e6627267a64 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -191,6 +191,8 @@ In order to deploy them, you can list the stacks you want to deploy. If your app If you want to deploy all of them, you can use the flag `--all` or the wildcard `*` to deploy all stacks in an app. Please note that, if you have a hierarchy of stacks as described above, `--all` and `*` will only match the stacks on the top level. If you want to match all the stacks in the hierarchy, use `**`. You can also combine these patterns. For example, if you want to deploy all stacks in the `Prod` stage, you can use `cdk deploy PipelineStack/Prod/**`. +`--concurrency N` allows deploying multiple stacks in parallel while respecting inter-stack dependencies to speed up deployments. It does not protect against CloudFormation and other AWS account rate limiting. + #### Parameters Pass parameters to your template during deployment by using `--parameters diff --git a/packages/aws-cdk/THIRD_PARTY_LICENSES b/packages/aws-cdk/THIRD_PARTY_LICENSES index 69a803d4f0d26..94ee54a0f4e82 100644 --- a/packages/aws-cdk/THIRD_PARTY_LICENSES +++ b/packages/aws-cdk/THIRD_PARTY_LICENSES @@ -1143,6 +1143,32 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +---------------- + +** eventemitter3@4.0.7 - https://www.npmjs.com/package/eventemitter3/v/4.0.7 | MIT +The MIT License (MIT) + +Copyright (c) 2014 Arnout Kazemier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + ---------------- ** fast-deep-equal@3.1.3 - https://www.npmjs.com/package/fast-deep-equal/v/3.1.3 | MIT @@ -2274,6 +2300,60 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +---------------- + +** p-finally@1.0.0 - https://www.npmjs.com/package/p-finally/v/1.0.0 | MIT +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +---------------- + +** p-queue@6.6.2 - https://www.npmjs.com/package/p-queue/v/6.6.2 | MIT +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +---------------- + +** p-timeout@3.2.0 - https://www.npmjs.com/package/p-timeout/v/3.2.0 | MIT +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + ---------------- ** pac-proxy-agent@5.0.0 - https://www.npmjs.com/package/pac-proxy-agent/v/5.0.0 | MIT diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index 724e0f02b579a..82dfd295ff5a2 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -14,6 +14,7 @@ import { CloudExecutable } from './api/cxapp/cloud-executable'; import { findCloudWatchLogGroups } from './api/logs/find-cloudwatch-logs'; import { CloudWatchLogEventMonitor } from './api/logs/logs-monitor'; import { StackActivityProgress } from './api/util/cloudformation/stack-activity-monitor'; +import { deployStacks } from './deploy'; import { printSecurityDiff, printStackDiff, RequireApproval } from './diff'; import { ResourceImporter } from './import'; import { data, debug, error, highlight, print, success, warning } from './logging'; @@ -137,7 +138,7 @@ export class CdkToolkit { } const startSynthTime = new Date().getTime(); - const stacks = await this.selectStacksForDeploy(options.selector, options.exclusively, options.cacheCloudAssembly); + const stackCollection = await this.selectStacksForDeploy(options.selector, options.exclusively, options.cacheCloudAssembly); const elapsedSynthTime = new Date().getTime() - startSynthTime; print('\n✨ Synthesis time: %ss\n', formatTime(elapsedSynthTime)); @@ -163,11 +164,19 @@ export class CdkToolkit { warning('⚠️ It should only be used for development - never use it for your production Stacks!'); } + const stacks = stackCollection.stackArtifacts; + const stackOutputs: { [key: string]: any } = { }; const outputsFile = options.outputsFile; - for (const stack of stacks.stackArtifacts) { - if (stacks.stackCount !== 1) { highlight(stack.displayName); } + const concurrency = options.concurrency || 1; + const progress = concurrency > 1 ? StackActivityProgress.EVENTS : options.progress; + if (concurrency > 1 && options.progress && options.progress != StackActivityProgress.EVENTS) { + warning('⚠️ The --concurrency flag only supports --progress "events". Switching to "events".'); + } + + const deployStack = async (stack: cxapi.CloudFormationStackArtifact) => { + if (stackCollection.stackCount !== 1) { highlight(stack.displayName); } if (!stack.environment) { // eslint-disable-next-line max-len throw new Error(`Stack ${stack.displayName} does not define an environment, and AWS credentials could not be obtained from standard locations or no region was configured.`); @@ -187,7 +196,7 @@ export class CdkToolkit { ci: options.ci, }); } - continue; + return; } if (requireApproval !== RequireApproval.Never) { @@ -201,6 +210,13 @@ export class CdkToolkit { 'but terminal (TTY) is not attached so we are unable to get a confirmation from the user'); } + // only talk to user if concurreny is 1 (otherwise, fail) + if (concurrency > 1) { + throw new Error( + '"--require-approval" is enabled and stack includes security-sensitive updates, ' + + 'but concurrency is greater than 1 so we are unable to get a confirmation from the user'); + } + const confirmed = await promptly.confirm('Do you wish to deploy these changes (y/n)?'); if (!confirmed) { throw new Error('Aborted by user'); } } @@ -229,7 +245,7 @@ export class CdkToolkit { force: options.force, parameters: Object.assign({}, parameterMap['*'], parameterMap[stack.stackName]), usePreviousParameters: options.usePreviousParameters, - progress: options.progress, + progress, ci: options.ci, rollback: options.rollback, hotswap: options.hotswap, @@ -278,6 +294,13 @@ export class CdkToolkit { } } print('\n✨ Total time: %ss\n', formatTime(elapsedSynthTime + elapsedDeployTime)); + }; + + try { + await deployStacks(stacks, { concurrency, deployStack }); + } catch (e) { + error('\n ❌ Deployment failed: %s', e); + throw e; } } @@ -948,6 +971,14 @@ export interface DeployOptions extends CfnDeployOptions, WatchOptions { * @default - not monitoring CloudWatch logs */ readonly cloudWatchLogMonitor?: CloudWatchLogEventMonitor; + + /** + * Maximum number of simulatenous deployments (dependency permitting) to execute. + * The default is '1', which executes all deployments serially. + * + * @default 1 + */ + readonly concurrency?: number; } export interface ImportOptions extends CfnDeployOptions { diff --git a/packages/aws-cdk/lib/cli.ts b/packages/aws-cdk/lib/cli.ts index c28e3a166f8fa..fcb3412a2717f 100644 --- a/packages/aws-cdk/lib/cli.ts +++ b/packages/aws-cdk/lib/cli.ts @@ -146,7 +146,8 @@ async function parseCommandLineArguments() { desc: 'Show CloudWatch log events from all resources in the selected Stacks in the terminal. ' + "'true' by default, use --no-logs to turn off. " + "Only in effect if specified alongside the '--watch' option", - }), + }) + .option('concurrency', { type: 'number', desc: 'Maximum number of simulatenous deployments (dependency permitting) to execute.', default: 1, requiresArg: true }), ) .command('import [STACK]', 'Import existing resource(s) into the given STACK', (yargs: Argv) => yargs .option('execute', { type: 'boolean', desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)', default: true }) @@ -480,6 +481,7 @@ async function initCommandLine() { hotswap: args.hotswap, watch: args.watch, traceLogs: args.logs, + concurrency: args.concurrency, }); case 'import': diff --git a/packages/aws-cdk/lib/deploy.ts b/packages/aws-cdk/lib/deploy.ts new file mode 100644 index 0000000000000..95f45e8d93299 --- /dev/null +++ b/packages/aws-cdk/lib/deploy.ts @@ -0,0 +1,60 @@ +import * as cxapi from '@aws-cdk/cx-api'; +import PQueue from 'p-queue'; + +type Options = { + concurrency: number; + deployStack: (stack: cxapi.CloudFormationStackArtifact) => Promise; +}; + +type DeploymentState = 'pending' | 'queued' | 'deploying' | 'completed' | 'failed' | 'skipped'; + +export const deployStacks = async (stacks: cxapi.CloudFormationStackArtifact[], { concurrency, deployStack }: Options): Promise => { + const queue = new PQueue({ concurrency }); + const deploymentStates = stacks.reduce((acc, stack) => ({ ...acc, [stack.id]: 'pending' as const }), {} as Record); + + const isStackUnblocked = (stack: cxapi.CloudFormationStackArtifact) => + stack.dependencies + .map(({ id }) => id) + .filter((id) => !id.endsWith('.assets')) + .every((id) => deploymentStates[id] === 'completed'); + + const hasAnyStackFailed = (states: Record) => Object.values(states).includes('failed'); + + const deploymentErrors: Error[] = []; + + const enqueueStackDeploys = () => { + stacks.forEach(async (stack) => { + if (deploymentStates[stack.id] === 'pending' && isStackUnblocked(stack)) { + deploymentStates[stack.id] = 'queued'; + + await queue.add(async () => { + // Do not start new deployments if any has already failed + if (hasAnyStackFailed(deploymentStates)) { + deploymentStates[stack.id] = 'skipped'; + return; + } + + deploymentStates[stack.id] = 'deploying'; + + await deployStack(stack).catch((err) => { + deploymentStates[stack.id] = 'failed'; + throw err; + }); + + deploymentStates[stack.id] = 'completed'; + enqueueStackDeploys(); + }).catch((err) => { + deploymentErrors.push(err); + }); + } + }); + }; + + enqueueStackDeploys(); + + await queue.onIdle(); + + if (deploymentErrors.length) { + throw Error(`Stack Deployments Failed: ${deploymentErrors}`); + } +}; \ No newline at end of file diff --git a/packages/aws-cdk/package.json b/packages/aws-cdk/package.json index a4c8238fbd091..c950840484a79 100644 --- a/packages/aws-cdk/package.json +++ b/packages/aws-cdk/package.json @@ -107,6 +107,7 @@ "glob": "^7.2.3", "json-diff": "^0.9.0", "minimatch": ">=3.1", + "p-queue": "^6.6.2", "promptly": "^3.2.0", "proxy-agent": "^5.0.0", "semver": "^7.3.7", diff --git a/packages/aws-cdk/test/deploy.test.ts b/packages/aws-cdk/test/deploy.test.ts new file mode 100644 index 0000000000000..600f47531dd95 --- /dev/null +++ b/packages/aws-cdk/test/deploy.test.ts @@ -0,0 +1,187 @@ +import * as cxapi from '@aws-cdk/cx-api'; +import { deployStacks } from '../lib/deploy'; + +type Stack = cxapi.CloudFormationStackArtifact; + +const sleep = async (duration: number) => new Promise((resolve) => setTimeout(() => resolve(), duration)); + +/** + * Repurposing unused stack attributes to create specific test scenarios + * - stack.name = deployment duration + * - stack.displayName = error message + */ +describe('DeployStacks', () => { + const deployedStacks: string[] = []; + const deployStack = async ({ id, displayName, name }: Stack) => { + const errorMessage = displayName; + const timeout = Number(name) || 0; + + await sleep(timeout); + + if (errorMessage) { + throw Error(errorMessage); + } + + deployedStacks.push(id); + }; + + beforeEach(() => { + deployedStacks.splice(0); + }); + + // Success + test.each([ + // Concurrency 1 + { scenario: 'No Stacks', concurrency: 1, toDeploy: [], expected: [] }, + { scenario: 'A', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }], expected: ['A'] }, + { scenario: 'A, B', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [] }], expected: ['A', 'B'] }, + { scenario: 'A -> B', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }], expected: ['A', 'B'] }, + { scenario: '[unsorted] A -> B', concurrency: 1, toDeploy: [{ id: 'B', dependencies: [{ id: 'A' }] }, { id: 'A', dependencies: [] }], expected: ['A', 'B'] }, + { scenario: 'A -> B -> C', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }, { id: 'C', dependencies: [{ id: 'B' }] }], expected: ['A', 'B', 'C'] }, + { scenario: 'A -> B, A -> C', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }, { id: 'C', dependencies: [{ id: 'A' }] }], expected: ['A', 'B', 'C'] }, + { + scenario: 'A (slow), B', + concurrency: 1, + toDeploy: [ + { id: 'A', dependencies: [], name: 10 }, + { id: 'B', dependencies: [] }, + ], + expected: ['A', 'B'], + }, + { + scenario: 'A -> B, C -> D', + concurrency: 1, + toDeploy: [ + { id: 'A', dependencies: [] }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expected: ['A', 'C', 'B', 'D'], + }, + { + scenario: 'A (slow) -> B, C -> D', + concurrency: 1, + toDeploy: [ + { id: 'A', dependencies: [], name: 10 }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expected: ['A', 'C', 'B', 'D'], + }, + + // Concurrency 2 + { scenario: 'No Stacks', concurrency: 2, toDeploy: [], expected: [] }, + { scenario: 'A', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }], expected: ['A'] }, + { scenario: 'A, B', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [] }], expected: ['A', 'B'] }, + { scenario: 'A -> B', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }], expected: ['A', 'B'] }, + { scenario: '[unsorted] A -> B', concurrency: 2, toDeploy: [{ id: 'B', dependencies: [{ id: 'A' }] }, { id: 'A', dependencies: [] }], expected: ['A', 'B'] }, + { scenario: 'A -> B -> C', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }, { id: 'C', dependencies: [{ id: 'B' }] }], expected: ['A', 'B', 'C'] }, + { scenario: 'A -> B, A -> C', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [{ id: 'A' }] }, { id: 'C', dependencies: [{ id: 'A' }] }], expected: ['A', 'B', 'C'] }, + { + scenario: 'A, B', + concurrency: 2, + toDeploy: [ + { id: 'A', dependencies: [], name: 10 }, + { id: 'B', dependencies: [] }, + ], + expected: ['B', 'A'], + }, + { + scenario: 'A -> B, C -> D', + concurrency: 2, + toDeploy: [ + { id: 'A', dependencies: [] }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expected: ['A', 'C', 'B', 'D'], + }, + { + scenario: 'A (slow) -> B, C -> D', + concurrency: 2, + toDeploy: [ + { id: 'A', dependencies: [], name: 10 }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expected: ['C', 'D', 'A', 'B'], + }, + ])('Success - Concurrency: $concurrency - $scenario', async ({ concurrency, expected, toDeploy }) => { + await expect(deployStacks(toDeploy as unknown as Stack[], { concurrency, deployStack })).resolves.toBeUndefined(); + + expect(deployedStacks).toStrictEqual(expected); + }); + + // Failure + test.each([ + // Concurrency 1 + { scenario: 'A (error)', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }], expectedError: 'A', expectedStacks: [] }, + { scenario: 'A (error), B', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }, { id: 'B', dependencies: [] }], expectedError: 'A', expectedStacks: [] }, + { scenario: 'A, B (error)', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [], displayName: 'B' }], expectedError: 'B', expectedStacks: ['A'] }, + { scenario: 'A (error) -> B', concurrency: 1, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }, { id: 'B', dependencies: [{ id: 'A' }] }], expectedError: 'A', expectedStacks: [] }, + { scenario: '[unsorted] A (error) -> B', concurrency: 1, toDeploy: [{ id: 'B', dependencies: [{ id: 'A' }] }, { id: 'A', dependencies: [], displayName: 'A' }], expectedError: 'A', expectedStacks: [] }, + { + scenario: 'A (error) -> B, C -> D', + concurrency: 1, + toDeploy: [ + { id: 'A', dependencies: [], displayName: 'A' }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expectedError: 'A', + expectedStacks: [], + }, + { + scenario: 'A -> B, C (error) -> D', + concurrency: 1, + toDeploy: [ + { id: 'A', dependencies: [] }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [], displayName: 'C', name: 100 }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expectedError: 'C', + expectedStacks: ['A'], + }, + + // Concurrency 2 + { scenario: 'A (error)', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }], expectedError: 'A', expectedStacks: [] }, + { scenario: 'A (error), B', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }, { id: 'B', dependencies: [] }], expectedError: 'A', expectedStacks: ['B'] }, + { scenario: 'A, B (error)', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [] }, { id: 'B', dependencies: [], displayName: 'B' }], expectedError: 'B', expectedStacks: ['A'] }, + { scenario: 'A (error) -> B', concurrency: 2, toDeploy: [{ id: 'A', dependencies: [], displayName: 'A' }, { id: 'B', dependencies: [{ id: 'A' }] }], expectedError: 'A', expectedStacks: [] }, + { scenario: '[unsorted] A (error) -> B', concurrency: 2, toDeploy: [{ id: 'B', dependencies: [{ id: 'A' }] }, { id: 'A', dependencies: [], displayName: 'A' }], expectedError: 'A', expectedStacks: [] }, + { + scenario: 'A (error) -> B, C -> D', + concurrency: 2, + toDeploy: [ + { id: 'A', dependencies: [], displayName: 'A' }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [] }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expectedError: 'A', + expectedStacks: ['C'], + }, + { + scenario: 'A -> B, C (error) -> D', + concurrency: 2, + toDeploy: [ + { id: 'A', dependencies: [] }, + { id: 'B', dependencies: [{ id: 'A' }] }, + { id: 'C', dependencies: [], displayName: 'C', name: 100 }, + { id: 'D', dependencies: [{ id: 'C' }] }, + ], + expectedError: 'C', + expectedStacks: ['A', 'B'], + }, + ])('Failure - Concurrency: $concurrency - $scenario', async ({ concurrency, expectedError, toDeploy, expectedStacks }) => { + await expect(deployStacks(toDeploy as unknown as Stack[], { concurrency, deployStack })).rejects.toThrowError(expectedError); + + expect(deployedStacks).toStrictEqual(expectedStacks); + }); +}); \ No newline at end of file diff --git a/packages/aws-cdk/test/integ/cli/cli.integtest.ts b/packages/aws-cdk/test/integ/cli/cli.integtest.ts index b3ff437771601..77315301329df 100644 --- a/packages/aws-cdk/test/integ/cli/cli.integtest.ts +++ b/packages/aws-cdk/test/integ/cli/cli.integtest.ts @@ -135,6 +135,14 @@ integTest('automatic ordering', withDefaultFixture(async (fixture) => { await fixture.cdkDestroy('order-providing'); })); +integTest('automatic ordering with concurrency', withDefaultFixture(async (fixture) => { + // Deploy the consuming stack which will include the producing stack + await fixture.cdkDeploy('order-consuming', { options: ['--concurrency', '2'] }); + + // Destroy the providing stack which will include the consuming stack + await fixture.cdkDestroy('order-providing'); +})); + integTest('context setting', withDefaultFixture(async (fixture) => { await fs.writeFile(path.join(fixture.integTestDir, 'cdk.context.json'), JSON.stringify({ contextkey: 'this is the context value', @@ -178,7 +186,17 @@ integTest('deploy', withDefaultFixture(async (fixture) => { integTest('deploy all', withDefaultFixture(async (fixture) => { const arns = await fixture.cdkDeploy('test-*', { captureStderr: false }); - // verify that we only deployed a single stack (there's a single ARN in the output) + // verify that we only deployed both stacks (there are 2 ARNs in the output) + expect(arns.split('\n').length).toEqual(2); +})); + +integTest('deploy all concurrently', withDefaultFixture(async (fixture) => { + const arns = await fixture.cdkDeploy('test-*', { + captureStderr: false, + options: ['--concurrency', '2'], + }); + + // verify that we only deployed both stacks (there are 2 ARNs in the output) expect(arns.split('\n').length).toEqual(2); })); diff --git a/packages/aws-cdk/tsconfig.json b/packages/aws-cdk/tsconfig.json index 674269068d4c5..2f37a56b99090 100644 --- a/packages/aws-cdk/tsconfig.json +++ b/packages/aws-cdk/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2019", + "target": "ES2020", "module": "commonjs", - "lib": ["es2019", "dom"], + "lib": ["es2019", "es2020", "dom"], "strict": true, "alwaysStrict": true, "declaration": true,