From 97b3b979c0a3cfc301acd772ba1ca7253a3f624d Mon Sep 17 00:00:00 2001 From: AWS CDK Team Date: Wed, 1 Sep 2021 07:59:20 +0000 Subject: [PATCH 01/10] chore(release): 1.121.0 --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ version.v1.json | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd16881355b70..22a49e715b1dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.121.0](https://github.com/aws/aws-cdk/compare/v1.120.0...v1.121.0) (2021-09-01) + + +### Features + +* **assertions:** 'not' matcher ([#16240](https://github.com/aws/aws-cdk/issues/16240)) ([b838f95](https://github.com/aws/aws-cdk/commit/b838f95f0905316fe706779381c93bedaa9ad504)), closes [#15868](https://github.com/aws/aws-cdk/issues/15868) +* **aws-cloudfront-origins:** add custom headers to S3Origin ([#16161](https://github.com/aws/aws-cdk/issues/16161)) ([f42b233](https://github.com/aws/aws-cdk/commit/f42b233a76ae810634fa43a25604dbc65bdd63b9)), closes [#16160](https://github.com/aws/aws-cdk/issues/16160) +* **cfnspec:** cloudformation spec v40.1.0 ([#16254](https://github.com/aws/aws-cdk/issues/16254)) ([fe81be7](https://github.com/aws/aws-cdk/commit/fe81be78322e3f1c23d2b02e59b56faa3b06e554)) +* **cli:** support `--no-rollback` flag ([#16293](https://github.com/aws/aws-cdk/issues/16293)) ([d763d90](https://github.com/aws/aws-cdk/commit/d763d9092289d0b28b2695b8474b44ed7d0bce54)), closes [#16289](https://github.com/aws/aws-cdk/issues/16289) +* **core:** normalize line endings in asset hash calculation ([#16276](https://github.com/aws/aws-cdk/issues/16276)) ([01bf6e2](https://github.com/aws/aws-cdk/commit/01bf6e2922994e7d41c8c6b171aa1693835f2b53)) +* **ec2:** add m6i instances ([#16081](https://github.com/aws/aws-cdk/issues/16081)) ([a42a1ea](https://github.com/aws/aws-cdk/commit/a42a1ea5a122f864936cdb0113b16fe92cc7205e)) +* **ecs:** add support for Fargate PV1.4 ephemeral storage ([#15440](https://github.com/aws/aws-cdk/issues/15440)) ([f1bf935](https://github.com/aws/aws-cdk/commit/f1bf935c47006096b33fb7bf0c847ffab9230870)), closes [#14570](https://github.com/aws/aws-cdk/issues/14570) +* **ecs-patterns:** add capacity provider strategies to queue processing service pattern ([#15684](https://github.com/aws/aws-cdk/issues/15684)) ([f40e8d6](https://github.com/aws/aws-cdk/commit/f40e8d6a502dd42e0a52d81f72abecaa2cdd920a)), closes [#14781](https://github.com/aws/aws-cdk/issues/14781) +* **ecs-patterns:** Allow configuration of SSL policy for listeners created by ECS patterns ([#15210](https://github.com/aws/aws-cdk/issues/15210)) ([2c3d21e](https://github.com/aws/aws-cdk/commit/2c3d21e2f1117a54510ba92748588ee95ab3631c)), closes [#11841](https://github.com/aws/aws-cdk/issues/11841) [#8816](https://github.com/aws/aws-cdk/issues/8816) +* **route53resolver:** DNS Firewall ([#15031](https://github.com/aws/aws-cdk/issues/15031)) ([ffdcd94](https://github.com/aws/aws-cdk/commit/ffdcd94405c160763e396a191d5af793ac8db998)) +* **stepfunctions-tasks:** support allocation strategies in EMR CreateCluster ([#16296](https://github.com/aws/aws-cdk/issues/16296)) ([5a5da57](https://github.com/aws/aws-cdk/commit/5a5da573149d45bf6e29bf7155715fa926804871)), closes [#16252](https://github.com/aws/aws-cdk/issues/16252) +* **synthetics:** add Python runtime and latest Nodejs runtime ([#16069](https://github.com/aws/aws-cdk/issues/16069)) ([de218ba](https://github.com/aws/aws-cdk/commit/de218ba3a294b5b98f93fc75a04ce42294e95008)), closes [#15138](https://github.com/aws/aws-cdk/issues/15138) [#16177](https://github.com/aws/aws-cdk/issues/16177) + + +### Bug Fixes + +* **apigatewayv2:** api mapping key with two hyphens is disallowed ([#16204](https://github.com/aws/aws-cdk/issues/16204)) ([0889564](https://github.com/aws/aws-cdk/commit/0889564a0c1b04d33909dd3fdb42147f23d67cbd)), closes [#15948](https://github.com/aws/aws-cdk/issues/15948) +* **aws-rds:** fromDatabaseInstanceAttributes incorrectly stringifies ports with tokens ([#16286](https://github.com/aws/aws-cdk/issues/16286)) ([41b831a](https://github.com/aws/aws-cdk/commit/41b831a6698ee6c7a3c8968bff8273a0c7f35448)), closes [#11813](https://github.com/aws/aws-cdk/issues/11813) +* **core:** inconsistent analytics string across operating systems ([#16300](https://github.com/aws/aws-cdk/issues/16300)) ([ff6082c](https://github.com/aws/aws-cdk/commit/ff6082caf7e534989fb8ee6b4c63c0c02e9a5ec0)), closes [#15322](https://github.com/aws/aws-cdk/issues/15322) +* **docs:** unnecessary log group in Step Functions state machine x-ray example ([#16159](https://github.com/aws/aws-cdk/issues/16159)) ([04d4547](https://github.com/aws/aws-cdk/commit/04d45474d80d3687a3fdf27f4d76dd1c8521eff0)) +* **elasticloadbalancingv2:** target group health check does not validate interval versus timeout ([#16107](https://github.com/aws/aws-cdk/issues/16107)) ([a85ad39](https://github.com/aws/aws-cdk/commit/a85ad392459c815d5c8e645dd3e8240d059024e6)), closes [#3703](https://github.com/aws/aws-cdk/issues/3703) + ## [1.120.0](https://github.com/aws/aws-cdk/compare/v1.119.0...v1.120.0) (2021-08-26) diff --git a/version.v1.json b/version.v1.json index 7ff9a577d56ba..be934684cecce 100644 --- a/version.v1.json +++ b/version.v1.json @@ -1,3 +1,3 @@ { - "version": "1.120.0" + "version": "1.121.0" } \ No newline at end of file From 1cf068dbf068d03ece47ed7617008ea7a55e0cdd Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 1 Sep 2021 11:08:06 +0300 Subject: [PATCH 02/10] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22a49e715b1dc..638fe5a43e6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. See [standa ### Features * **assertions:** 'not' matcher ([#16240](https://github.com/aws/aws-cdk/issues/16240)) ([b838f95](https://github.com/aws/aws-cdk/commit/b838f95f0905316fe706779381c93bedaa9ad504)), closes [#15868](https://github.com/aws/aws-cdk/issues/15868) -* **aws-cloudfront-origins:** add custom headers to S3Origin ([#16161](https://github.com/aws/aws-cdk/issues/16161)) ([f42b233](https://github.com/aws/aws-cdk/commit/f42b233a76ae810634fa43a25604dbc65bdd63b9)), closes [#16160](https://github.com/aws/aws-cdk/issues/16160) +* **cloudfront-origins:** add custom headers to S3Origin ([#16161](https://github.com/aws/aws-cdk/issues/16161)) ([f42b233](https://github.com/aws/aws-cdk/commit/f42b233a76ae810634fa43a25604dbc65bdd63b9)), closes [#16160](https://github.com/aws/aws-cdk/issues/16160) * **cfnspec:** cloudformation spec v40.1.0 ([#16254](https://github.com/aws/aws-cdk/issues/16254)) ([fe81be7](https://github.com/aws/aws-cdk/commit/fe81be78322e3f1c23d2b02e59b56faa3b06e554)) * **cli:** support `--no-rollback` flag ([#16293](https://github.com/aws/aws-cdk/issues/16293)) ([d763d90](https://github.com/aws/aws-cdk/commit/d763d9092289d0b28b2695b8474b44ed7d0bce54)), closes [#16289](https://github.com/aws/aws-cdk/issues/16289) * **core:** normalize line endings in asset hash calculation ([#16276](https://github.com/aws/aws-cdk/issues/16276)) ([01bf6e2](https://github.com/aws/aws-cdk/commit/01bf6e2922994e7d41c8c6b171aa1693835f2b53)) From 78b4660db79ce4dd3974b074d828414054bb9179 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Wed, 1 Sep 2021 11:08:39 +0300 Subject: [PATCH 03/10] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 638fe5a43e6e2..e50659a3c7123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file. See [standa ### Bug Fixes * **apigatewayv2:** api mapping key with two hyphens is disallowed ([#16204](https://github.com/aws/aws-cdk/issues/16204)) ([0889564](https://github.com/aws/aws-cdk/commit/0889564a0c1b04d33909dd3fdb42147f23d67cbd)), closes [#15948](https://github.com/aws/aws-cdk/issues/15948) -* **aws-rds:** fromDatabaseInstanceAttributes incorrectly stringifies ports with tokens ([#16286](https://github.com/aws/aws-cdk/issues/16286)) ([41b831a](https://github.com/aws/aws-cdk/commit/41b831a6698ee6c7a3c8968bff8273a0c7f35448)), closes [#11813](https://github.com/aws/aws-cdk/issues/11813) +* **rds:** fromDatabaseInstanceAttributes incorrectly stringifies ports with tokens ([#16286](https://github.com/aws/aws-cdk/issues/16286)) ([41b831a](https://github.com/aws/aws-cdk/commit/41b831a6698ee6c7a3c8968bff8273a0c7f35448)), closes [#11813](https://github.com/aws/aws-cdk/issues/11813) * **core:** inconsistent analytics string across operating systems ([#16300](https://github.com/aws/aws-cdk/issues/16300)) ([ff6082c](https://github.com/aws/aws-cdk/commit/ff6082caf7e534989fb8ee6b4c63c0c02e9a5ec0)), closes [#15322](https://github.com/aws/aws-cdk/issues/15322) * **docs:** unnecessary log group in Step Functions state machine x-ray example ([#16159](https://github.com/aws/aws-cdk/issues/16159)) ([04d4547](https://github.com/aws/aws-cdk/commit/04d45474d80d3687a3fdf27f4d76dd1c8521eff0)) * **elasticloadbalancingv2:** target group health check does not validate interval versus timeout ([#16107](https://github.com/aws/aws-cdk/issues/16107)) ([a85ad39](https://github.com/aws/aws-cdk/commit/a85ad392459c815d5c8e645dd3e8240d059024e6)), closes [#3703](https://github.com/aws/aws-cdk/issues/3703) From 74af7afc6a741061a40d28892d6164a7d39f8a92 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Wed, 1 Sep 2021 10:00:13 +0100 Subject: [PATCH 04/10] Apply suggestions from code review --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e50659a3c7123..0c4b63bd89989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,8 @@ All notable changes to this project will be documented in this file. See [standa ### Bug Fixes * **apigatewayv2:** api mapping key with two hyphens is disallowed ([#16204](https://github.com/aws/aws-cdk/issues/16204)) ([0889564](https://github.com/aws/aws-cdk/commit/0889564a0c1b04d33909dd3fdb42147f23d67cbd)), closes [#15948](https://github.com/aws/aws-cdk/issues/15948) -* **rds:** fromDatabaseInstanceAttributes incorrectly stringifies ports with tokens ([#16286](https://github.com/aws/aws-cdk/issues/16286)) ([41b831a](https://github.com/aws/aws-cdk/commit/41b831a6698ee6c7a3c8968bff8273a0c7f35448)), closes [#11813](https://github.com/aws/aws-cdk/issues/11813) +* **rds:** `fromDatabaseInstanceAttributes()` incorrectly stringifies ports with tokens ([#16286](https://github.com/aws/aws-cdk/issues/16286)) ([41b831a](https://github.com/aws/aws-cdk/commit/41b831a6698ee6c7a3c8968bff8273a0c7f35448)), closes [#11813](https://github.com/aws/aws-cdk/issues/11813) * **core:** inconsistent analytics string across operating systems ([#16300](https://github.com/aws/aws-cdk/issues/16300)) ([ff6082c](https://github.com/aws/aws-cdk/commit/ff6082caf7e534989fb8ee6b4c63c0c02e9a5ec0)), closes [#15322](https://github.com/aws/aws-cdk/issues/15322) -* **docs:** unnecessary log group in Step Functions state machine x-ray example ([#16159](https://github.com/aws/aws-cdk/issues/16159)) ([04d4547](https://github.com/aws/aws-cdk/commit/04d45474d80d3687a3fdf27f4d76dd1c8521eff0)) * **elasticloadbalancingv2:** target group health check does not validate interval versus timeout ([#16107](https://github.com/aws/aws-cdk/issues/16107)) ([a85ad39](https://github.com/aws/aws-cdk/commit/a85ad392459c815d5c8e645dd3e8240d059024e6)), closes [#3703](https://github.com/aws/aws-cdk/issues/3703) ## [1.120.0](https://github.com/aws/aws-cdk/compare/v1.119.0...v1.120.0) (2021-08-26) From 61c251c21887ca15184618d7ab858b6a7907f96d Mon Sep 17 00:00:00 2001 From: Madeline Kusters <80541297+madeline-k@users.noreply.github.com> Date: Wed, 1 Sep 2021 10:26:00 -0700 Subject: [PATCH 05/10] chore(resolve-version): export the alphaVersion (#16321) This will be used by a change in `tools/individual-pkg-gen/copy-files-removing-deps.ts` on the `v2-main` branch, so that the `transform` step can correctly set the `version` key and the version for each dependency in each alpha module's `package.json` file. See https://github.com/aws/aws-cdk/pull/16322 for usage. Part of #15591 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- scripts/resolve-version-lib.js | 4 +- scripts/script-tests/resolve-version.test.js | 39 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/scripts/resolve-version-lib.js b/scripts/resolve-version-lib.js index ec1f7b1b83822..5885d96b6afd9 100755 --- a/scripts/resolve-version-lib.js +++ b/scripts/resolve-version-lib.js @@ -37,7 +37,8 @@ function resolveVersion(rootdir) { // validate that current version matches the requirements // - const currentVersion = require(versionFilePath).version; + const versions = require(versionFilePath); + const currentVersion = versions.version; if (!currentVersion.startsWith(`${majorVersion}.`)) { throw new Error(`current version "${currentVersion}" does not use the expected major version ${majorVersion}`); } @@ -68,6 +69,7 @@ function resolveVersion(rootdir) { return { version: currentVersion, + alphaVersion: versions.alphaVersion, versionFile, changelogFile, alphaChangelogFile, diff --git a/scripts/script-tests/resolve-version.test.js b/scripts/script-tests/resolve-version.test.js index 693e29234f023..1cabbb2acd795 100644 --- a/scripts/script-tests/resolve-version.test.js +++ b/scripts/script-tests/resolve-version.test.js @@ -17,6 +17,24 @@ happy({ marker: '0.0.0', prerelease: undefined, version: '2.1.0', + alphaVersion: undefined, + versionFile: 'version.v2.json' + } +}); + +happy({ + name: 'stable release with alpha modules', + inputs: { + 'release.json': { majorVersion: 2, releaseType: 'stable' }, + 'version.v2.json': { version: '2.1.0', alphaVersion: '2.1.0-alpha' }, + }, + expected: { + changelogFile: 'CHANGELOG.v2.md', + alphaChangelogFile: 'CHANGELOG.v2.alpha.md', + marker: '0.0.0', + prerelease: undefined, + version: '2.1.0', + alphaVersion: '2.1.0-alpha', versionFile: 'version.v2.json' } }); @@ -33,6 +51,7 @@ happy({ marker: '0.0.0', prerelease: 'alpha', version: '2.1.0-alpha.0', + alphaVersion: undefined, versionFile: 'version.v2.json' } }); @@ -49,6 +68,24 @@ happy({ marker: '0.0.0', prerelease: 'rc', version: '2.1.0-rc.0', + alphaVersion: undefined, + versionFile: 'version.v2.json' + } +}); + +happy({ + name: 'rc release with alpha modules', + inputs: { + 'release.json': { majorVersion: 2, releaseType: 'rc' }, + 'version.v2.json': { version: '2.0.0-rc.0', alphaVersion: '2.0.0-alpha.0' }, + }, + expected: { + changelogFile: 'CHANGELOG.v2.md', + alphaChangelogFile: 'CHANGELOG.v2.alpha.md', + marker: '0.0.0', + prerelease: 'rc', + version: '2.0.0-rc.0', + alphaVersion: '2.0.0-alpha.0', versionFile: 'version.v2.json' } }); @@ -65,6 +102,7 @@ happy({ marker: '0.0.0', prerelease: undefined, version: '1.72.0', + alphaVersion: undefined, versionFile: 'version.v1.json' } }); @@ -81,6 +119,7 @@ happy({ marker: '0.0.0', prerelease: undefined, version: '2.0.0-rc.0', + alphaVersion: undefined, versionFile: 'version.v2.json' } }); From 839fdb90f4d68bf0f49fe6b8358af2870acb891d Mon Sep 17 00:00:00 2001 From: Nick Lynch Date: Wed, 1 Sep 2021 19:20:28 +0100 Subject: [PATCH 06/10] chore(yarn-cling): rename test packages to real package names (#16325) The tests for `yarn-cling` currently reference what were imaginary package names as placeholders; those package names have now been registered. While this has no practical impact, switching the package names to be ones we own just so there's no ambiguity. An `npm install` is never done on these directories, so the packages chosen really doesn't matter. Just picked two of our favorites at random. :) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- tools/yarn-cling/.gitignore | 4 +-- tools/yarn-cling/package.json | 2 +- tools/yarn-cling/test/cling.test.ts | 32 +++++++++---------- .../{package2 => cdk}/package.json | 2 +- .../node_modules/aws-cdk-lib/package.json | 4 +++ .../jsii/node_modules/aws-cdk/package.json | 7 ++++ .../test/test-fixture/jsii/node_modules/cdk | 1 + .../test/test-fixture/jsii/package.json | 8 +++++ .../package1/node_modules/package2 | 1 - .../registrydependency1/package.json | 7 ---- .../registrydependency2/package.json | 4 --- .../test/test-fixture/package1/package.json | 8 ----- tools/yarn-cling/test/test-fixture/yarn.lock | 4 +-- 13 files changed, 42 insertions(+), 42 deletions(-) rename tools/yarn-cling/test/test-fixture/{package2 => cdk}/package.json (52%) create mode 100644 tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json create mode 100644 tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json create mode 120000 tools/yarn-cling/test/test-fixture/jsii/node_modules/cdk create mode 100644 tools/yarn-cling/test/test-fixture/jsii/package.json delete mode 120000 tools/yarn-cling/test/test-fixture/package1/node_modules/package2 delete mode 100644 tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency1/package.json delete mode 100644 tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency2/package.json delete mode 100644 tools/yarn-cling/test/test-fixture/package1/package.json diff --git a/tools/yarn-cling/.gitignore b/tools/yarn-cling/.gitignore index 884f5381e01ab..bef31def37928 100644 --- a/tools/yarn-cling/.gitignore +++ b/tools/yarn-cling/.gitignore @@ -11,5 +11,5 @@ dist coverage nyc.config.js !.eslintrc.js -!test/test-fixture/package1/node_modules/ -junit.xml \ No newline at end of file +!test/test-fixture/jsii/node_modules/ +junit.xml diff --git a/tools/yarn-cling/package.json b/tools/yarn-cling/package.json index 52501bf50f83e..9d86cc671b4d4 100644 --- a/tools/yarn-cling/package.json +++ b/tools/yarn-cling/package.json @@ -16,7 +16,7 @@ "build": "tsc", "watch": "tsc -w", "pkglint": "pkglint -f", - "test": "ln -sf ../../package2 test/test-fixture/package1/node_modules/ && jest", + "test": "ln -sf ../../cdk test/test-fixture/jsii/node_modules/ && jest", "build+test+package": "yarn build+test", "build+test": "yarn build && yarn test", "build+extract": "yarn build", diff --git a/tools/yarn-cling/test/cling.test.ts b/tools/yarn-cling/test/cling.test.ts index 1628d2415a1ae..f56e98f535f91 100644 --- a/tools/yarn-cling/test/cling.test.ts +++ b/tools/yarn-cling/test/cling.test.ts @@ -3,22 +3,22 @@ import { checkRequiredVersions, generateShrinkwrap } from '../lib'; test('generate lock for fixture directory', async () => { const lockFile = await generateShrinkwrap({ - packageJsonFile: path.join(__dirname, 'test-fixture', 'package1', 'package.json'), + packageJsonFile: path.join(__dirname, 'test-fixture', 'jsii', 'package.json'), hoist: false, }); expect(lockFile).toEqual({ lockfileVersion: 1, - name: 'package1', + name: 'jsii', requires: true, version: '1.1.1', dependencies: { - package2: { + 'cdk': { version: '2.2.2', }, - registrydependency1: { + 'aws-cdk': { dependencies: { - registrydependency2: { + 'aws-cdk-lib': { integrity: 'sha512-pineapple', resolved: 'https://registry.bla.com/stuff', version: '2.3.999', @@ -26,7 +26,7 @@ test('generate lock for fixture directory', async () => { }, integrity: 'sha512-banana', requires: { - registrydependency2: '^2.3.4', + 'aws-cdk-lib': '^2.3.4', }, resolved: 'https://registry.bla.com/stuff', version: '1.2.999', @@ -37,28 +37,28 @@ test('generate lock for fixture directory', async () => { test('generate hoisted lock for fixture directory', async () => { const lockFile = await generateShrinkwrap({ - packageJsonFile: path.join(__dirname, 'test-fixture', 'package1', 'package.json'), + packageJsonFile: path.join(__dirname, 'test-fixture', 'jsii', 'package.json'), hoist: true, }); expect(lockFile).toEqual({ lockfileVersion: 1, - name: 'package1', + name: 'jsii', requires: true, version: '1.1.1', dependencies: { - package2: { + 'cdk': { version: '2.2.2', }, - registrydependency1: { + 'aws-cdk': { integrity: 'sha512-banana', requires: { - registrydependency2: '^2.3.4', + 'aws-cdk-lib': '^2.3.4', }, resolved: 'https://registry.bla.com/stuff', version: '1.2.999', }, - registrydependency2: { + 'aws-cdk-lib': { integrity: 'sha512-pineapple', resolved: 'https://registry.bla.com/stuff', version: '2.3.999', @@ -70,17 +70,17 @@ test('generate hoisted lock for fixture directory', async () => { test('fail when requires cannot be satisfied', async () => { const lockFile = { lockfileVersion: 1, - name: 'package1', + name: 'jsii', requires: true, version: '1.1.1', dependencies: { - package1: { + jsii: { version: '2.2.2', requires: { - package2: '^3.3.3', // <- this needs to be adjusted + cdk: '^3.3.3', // <- this needs to be adjusted }, }, - package2: { + cdk: { version: '4.4.4', }, }, diff --git a/tools/yarn-cling/test/test-fixture/package2/package.json b/tools/yarn-cling/test/test-fixture/cdk/package.json similarity index 52% rename from tools/yarn-cling/test/test-fixture/package2/package.json rename to tools/yarn-cling/test/test-fixture/cdk/package.json index d10f139d13944..8594e124f71b7 100644 --- a/tools/yarn-cling/test/test-fixture/package2/package.json +++ b/tools/yarn-cling/test/test-fixture/cdk/package.json @@ -1,4 +1,4 @@ { - "name": "package2", + "name": "cdk", "version": "2.2.2" } diff --git a/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json b/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json new file mode 100644 index 0000000000000..2721d93a758df --- /dev/null +++ b/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk-lib/package.json @@ -0,0 +1,4 @@ +{ + "name": "aws-cdk-lib", + "version": "2.3.999" +} diff --git a/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json b/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json new file mode 100644 index 0000000000000..f074216bccb3b --- /dev/null +++ b/tools/yarn-cling/test/test-fixture/jsii/node_modules/aws-cdk/package.json @@ -0,0 +1,7 @@ +{ + "name": "aws-cdk", + "version": "1.2.999", + "dependencies": { + "aws-cdk-lib": "^2.3.4" + } +} diff --git a/tools/yarn-cling/test/test-fixture/jsii/node_modules/cdk b/tools/yarn-cling/test/test-fixture/jsii/node_modules/cdk new file mode 120000 index 0000000000000..7ce3fadc4aadf --- /dev/null +++ b/tools/yarn-cling/test/test-fixture/jsii/node_modules/cdk @@ -0,0 +1 @@ +../../cdk \ No newline at end of file diff --git a/tools/yarn-cling/test/test-fixture/jsii/package.json b/tools/yarn-cling/test/test-fixture/jsii/package.json new file mode 100644 index 0000000000000..8508d1f52fc9e --- /dev/null +++ b/tools/yarn-cling/test/test-fixture/jsii/package.json @@ -0,0 +1,8 @@ +{ + "name": "jsii", + "version": "1.1.1", + "dependencies": { + "aws-cdk": "^1.2.3", + "cdk": "2.2.2" + } +} diff --git a/tools/yarn-cling/test/test-fixture/package1/node_modules/package2 b/tools/yarn-cling/test/test-fixture/package1/node_modules/package2 deleted file mode 120000 index 8db12e196dfbd..0000000000000 --- a/tools/yarn-cling/test/test-fixture/package1/node_modules/package2 +++ /dev/null @@ -1 +0,0 @@ -../../package2 \ No newline at end of file diff --git a/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency1/package.json b/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency1/package.json deleted file mode 100644 index 8ecbc5b50e2e6..0000000000000 --- a/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency1/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "registrydependency1", - "version": "1.2.999", - "dependencies": { - "registrydependency2": "^2.3.4" - } -} diff --git a/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency2/package.json b/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency2/package.json deleted file mode 100644 index 8b9d7f39ababd..0000000000000 --- a/tools/yarn-cling/test/test-fixture/package1/node_modules/registrydependency2/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "registrydependency2", - "version": "2.3.999" -} diff --git a/tools/yarn-cling/test/test-fixture/package1/package.json b/tools/yarn-cling/test/test-fixture/package1/package.json deleted file mode 100644 index 8edf6d46e6537..0000000000000 --- a/tools/yarn-cling/test/test-fixture/package1/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "package1", - "version": "1.1.1", - "dependencies": { - "registrydependency1": "^1.2.3", - "package2": "2.2.2" - } -} diff --git a/tools/yarn-cling/test/test-fixture/yarn.lock b/tools/yarn-cling/test/test-fixture/yarn.lock index fda733502a052..bb94543e94422 100644 --- a/tools/yarn-cling/test/test-fixture/yarn.lock +++ b/tools/yarn-cling/test/test-fixture/yarn.lock @@ -1,9 +1,9 @@ -"registrydependency1@^1.2.3": +"aws-cdk@^1.2.3": version "1.2.999" resolved "https://registry.bla.com/stuff" integrity sha512-banana -"registrydependency2@^2.3.4": +"aws-cdk-lib@^2.3.4": version "2.3.999" resolved "https://registry.bla.com/stuff" integrity sha512-pineapple From 66baca58adc294d5c5924cf8f8c5fa122c6d6dfc Mon Sep 17 00:00:00 2001 From: Unnati Parekh <80710604+upparekh@users.noreply.github.com> Date: Wed, 1 Sep 2021 13:50:54 -0700 Subject: [PATCH 07/10] feat(ecs-service-extensions): Subscribe Extension (#16049) ---- This PR adds a new service extension, `SubscribeExtension`. This extension can be added to a service to create SQS Queues which can subscribe to the SNS Topics provided by the user. It creates a default SQS Queue called `eventsQueue` . It also supports creation of topic-specific queues and sets up the SNS subscriptions accordingly. The created topic-queue subscriptions can be accessed using `subscriptions` field of the extension and the default queue for this service can be accessed using the `eventsQueue` getter method. (This PR does not include autoscaling, will be adding it in a separate PR) *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../ecs-service-extensions/README.md | 35 ++ .../lib/extensions/index.ts | 1 + .../lib/extensions/queue.ts | 212 ++++++++ .../ecs-service-extensions/package.json | 4 + .../ecs-service-extensions/test/test.queue.ts | 508 ++++++++++++++++++ 5 files changed, 760 insertions(+) create mode 100644 packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts create mode 100644 packages/@aws-cdk-containers/ecs-service-extensions/test/test.queue.ts diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/README.md b/packages/@aws-cdk-containers/ecs-service-extensions/README.md index f3845e69a55e5..53e4d2b6f3c56 100644 --- a/packages/@aws-cdk-containers/ecs-service-extensions/README.md +++ b/packages/@aws-cdk-containers/ecs-service-extensions/README.md @@ -19,6 +19,7 @@ The `Service` construct provided by this module can be extended with optional `S - [AWS AppMesh](https://aws.amazon.com/app-mesh/) for adding your application to a service mesh - [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html), for exposing your service to the public - [AWS FireLens](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html), for filtering and routing application logs +- Queue to allow your service to consume messages from an SQS Queue which is populated by one or more SNS Topics that it is subscribed to - [Community Extensions](#community-extensions), providing support for advanced use cases The `ServiceExtension` class is an abstract class which you can also implement in @@ -321,6 +322,40 @@ const environment = Environment.fromEnvironmentAttributes(stack, 'Environment', ``` +## Queue Extension + +This service extension creates a default SQS Queue `eventsQueue` for the service (if not provided) and accepts a list of `ISubscribable` objects that the `eventsQueue` can subscribe to. The service extension creates the subscriptions and sets up permissions for the service to consume messages from the SQS Queue. + +### Setting up SNS Topic Subscriptions for SQS Queues + +You can use this extension to set up SNS Topic subscriptions for the `eventsQueue`. To do this, create a new object of type `TopicSubscription` for every SNS Topic you want the `eventsQueue` to subscribe to and provide it as input to the service extension. + +```ts +const myServiceDescription = nameDescription.add(new QueueExtension({ + // Provide list of topic subscriptions that you want the `eventsQueue` to subscribe to + subscriptions: [new TopicSubscription({ + topic: new sns.Topic(stack, 'my-topic'), + }], +})); + +// To access the `eventsQueue` for the service, use the `eventsQueue` getter for the extension +const myQueueExtension = myServiceDescription.extensions.queue as QueueExtension; +const myEventsQueue = myQueueExtension.eventsQueue; +``` + +For setting up a topic-specific queue subscription, you can provide a custom queue in the `TopicSubscription` object along with the SNS Topic. The extension will set up a topic subscription for the provided queue instead of the default `eventsQueue` of the service. + +```ts +nameDescription.add(new QueueExtension({ + queue: myEventsQueue, + subscriptions: [new TopicSubscription({ + topic: new sns.Topic(stack, 'my-topic'), + // `myTopicQueue` will subscribe to the `my-topic` instead of `eventsQueue` + queue: myTopicQueue, + }], +})); +``` + ## Community Extensions We encourage the development of Community Service Extensions that support diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/index.ts b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/index.ts index 4e464e0d0734e..78c138aba0102 100644 --- a/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/index.ts +++ b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/index.ts @@ -6,3 +6,4 @@ export * from './cloudwatch-agent'; export * from './scale-on-cpu-utilization'; export * from './xray'; export * from './assign-public-ip'; +export * from './queue'; \ No newline at end of file diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts new file mode 100644 index 0000000000000..d43b587d6326e --- /dev/null +++ b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts @@ -0,0 +1,212 @@ +import * as ecs from '@aws-cdk/aws-ecs'; +import * as sns from '@aws-cdk/aws-sns'; +import * as subscription from '@aws-cdk/aws-sns-subscriptions'; +import * as sqs from '@aws-cdk/aws-sqs'; +import * as cdk from '@aws-cdk/core'; +import { Service } from '../service'; +import { Container } from './container'; +import { ContainerMutatingHook, ServiceExtension } from './extension-interfaces'; + +// Keep this import separate from other imports to reduce chance for merge conflicts with v2-main +// eslint-disable-next-line no-duplicate-imports, import/order +import { Construct } from '@aws-cdk/core'; + +/** + * An interface that will be implemented by all the resources that can be subscribed to. + */ +export interface ISubscribable { + /** + * All classes implementing this interface must also implement the `subscribe()` method + */ + subscribe(extension: QueueExtension): sqs.IQueue; +} + +/** + * The settings for the Queue extension. + */ +export interface QueueExtensionProps { + /** + * The list of subscriptions for this service. + * + * @default none + */ + readonly subscriptions?: ISubscribable[]; + + /** + * The user-provided default queue for this service. + * + * @default If the `eventsQueue` is not provided, a default SQS Queue is created for the service. + */ + readonly eventsQueue?: sqs.IQueue; +} + +/** + * The topic-specific settings for creating the queue subscriptions. + */ +export interface TopicSubscriptionProps { + /** + * The SNS Topic to subscribe to. + */ + readonly topic: sns.ITopic; + + /** + * The user-provided queue to subscribe to the given topic. + * If the `queue` is not provided, the default `eventsQueue` will subscribe to the given topic. + * + * @default none + */ + readonly queue?: sqs.IQueue; +} + +/** + * The `TopicSubscription` class represents an SNS Topic resource that can be subscribed to by the service queues. + */ +export class TopicSubscription implements ISubscribable { + public readonly topic: sns.ITopic; + + public readonly queue?: sqs.IQueue; + + constructor(props: TopicSubscriptionProps) { + this.topic = props.topic; + this.queue = props.queue; + } + + /** + * This method sets up SNS Topic subscriptions for the SQS queue provided by the user. If a `queue` is not provided, + * the default `eventsQueue` subscribes to the given topic. + * + * @param extension `QueueExtension` added to the service + * @returns the queue subscribed to the given topic + */ + public subscribe(extension: QueueExtension) : sqs.IQueue { + let queue = extension.eventsQueue; + if (this.queue) { + queue = this.queue; + } + this.topic.addSubscription(new subscription.SqsSubscription(queue)); + return queue; + } +} + +/** + * Settings for the hook which mutates the application container + * to add the events queue URI to its environment. + */ +interface ContainerMutatingProps { + /** + * The events queue name and URI to be added to the container environment. + */ + readonly environment: { [key: string]: string }; +} + +/** + * This hook modifies the application container's environment to + * add the queue URL for the events queue of the service. + */ +class QueueExtensionMutatingHook extends ContainerMutatingHook { + private environment: { [key: string]: string }; + + constructor(props: ContainerMutatingProps) { + super(); + this.environment = props.environment; + } + + public mutateContainerDefinition(props: ecs.ContainerDefinitionOptions): ecs.ContainerDefinitionOptions { + return { + ...props, + + environment: { ...(props.environment || {}), ...this.environment }, + } as ecs.ContainerDefinitionOptions; + } +} + +/** + * This extension creates a default `eventsQueue` for the service (if not provided) and accepts a list of objects of + * type `ISubscribable` that the `eventsQueue` subscribes to. It creates the subscriptions and sets up permissions + * for the service to consume messages from the SQS Queues. + * + * The default queue for this service can be accessed using the getter `.eventsQueue`. + */ +export class QueueExtension extends ServiceExtension { + private _eventsQueue!: sqs.IQueue; + + private subscriptionQueues = new Set(); + + private environment: { [key: string]: string } = {}; + + private props?: QueueExtensionProps; + + constructor(props?: QueueExtensionProps) { + super('queue'); + + this.props = props; + } + + /** + * This hook creates (if required) and sets the default queue `eventsQueue`. It also sets up the subscriptions for + * the provided `ISubscribable` objects. + * + * @param service The parent service which this extension has been added to + * @param scope The scope that this extension should create resources in + */ + public prehook(service: Service, scope: Construct) { + this.parentService = service; + this.scope = scope; + + let eventsQueue = this.props?.eventsQueue; + if (!eventsQueue) { + const deadLetterQueue = new sqs.Queue(this.scope, 'EventsDeadLetterQueue', { + retentionPeriod: cdk.Duration.days(14), + }); + + eventsQueue = new sqs.Queue(this.scope, 'EventsQueue', { + deadLetterQueue: { + queue: deadLetterQueue, + maxReceiveCount: 3, + }, + }); + } + this._eventsQueue = eventsQueue; + + this.environment[`${this.parentService.id.toUpperCase()}_QUEUE_URI`] = this._eventsQueue.queueUrl; + + if (this.props?.subscriptions) { + for (const subs of this.props.subscriptions) { + const subsQueue = subs.subscribe(this); + this.subscriptionQueues.add(subsQueue); + } + } + } + + /** + * Add hooks to the main application extension so that it is modified to + * add the events queue URL to the container environment. + */ + public addHooks() { + const container = this.parentService.serviceDescription.get('service-container') as Container; + + if (!container) { + throw new Error('Queue Extension requires an application extension'); + } + + container.addContainerMutatingHook(new QueueExtensionMutatingHook({ + environment: this.environment, + })); + } + + /** + * After the task definition has been created, this hook grants SQS permissions to the task role. + * + * @param taskDefinition The created task definition + */ + public useTaskDefinition(taskDefinition: ecs.TaskDefinition) { + this._eventsQueue.grantConsumeMessages(taskDefinition.taskRole); + for (const queue of this.subscriptionQueues) { + queue.grantConsumeMessages(taskDefinition.taskRole); + } + } + + public get eventsQueue() : sqs.IQueue { + return this._eventsQueue; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/package.json b/packages/@aws-cdk-containers/ecs-service-extensions/package.json index 0d99dadbedb02..444e43ba9a19a 100644 --- a/packages/@aws-cdk-containers/ecs-service-extensions/package.json +++ b/packages/@aws-cdk-containers/ecs-service-extensions/package.json @@ -64,6 +64,8 @@ "@aws-cdk/aws-route53": "0.0.0", "@aws-cdk/aws-route53-targets": "0.0.0", "@aws-cdk/aws-servicediscovery": "0.0.0", + "@aws-cdk/aws-sns": "0.0.0", + "@aws-cdk/aws-sns-subscriptions": "0.0.0", "@aws-cdk/aws-sqs": "0.0.0", "@aws-cdk/core": "0.0.0", "@aws-cdk/custom-resources": "0.0.0", @@ -89,6 +91,8 @@ "@aws-cdk/aws-route53": "0.0.0", "@aws-cdk/aws-route53-targets": "0.0.0", "@aws-cdk/aws-servicediscovery": "0.0.0", + "@aws-cdk/aws-sns": "0.0.0", + "@aws-cdk/aws-sns-subscriptions": "0.0.0", "@aws-cdk/aws-sqs": "0.0.0", "@aws-cdk/core": "0.0.0", "@aws-cdk/custom-resources": "0.0.0", diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/test/test.queue.ts b/packages/@aws-cdk-containers/ecs-service-extensions/test/test.queue.ts new file mode 100644 index 0000000000000..ec2fb234c16ce --- /dev/null +++ b/packages/@aws-cdk-containers/ecs-service-extensions/test/test.queue.ts @@ -0,0 +1,508 @@ +import { countResources, expect, haveResource } from '@aws-cdk/assert-internal'; +import * as ecs from '@aws-cdk/aws-ecs'; +import * as sns from '@aws-cdk/aws-sns'; +import * as sqs from '@aws-cdk/aws-sqs'; +import * as cdk from '@aws-cdk/core'; +import { Test } from 'nodeunit'; +import { Container, Environment, QueueExtension, Service, ServiceDescription, TopicSubscription } from '../lib'; + +export = { + 'should only create a default queue when no input props are provided'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + const environment = new Environment(stack, 'production'); + const serviceDescription = new ServiceDescription(); + + serviceDescription.add(new Container({ + cpu: 256, + memoryMiB: 512, + trafficPort: 80, + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + environment: { + PORT: '80', + }, + })); + + // WHEN + serviceDescription.add(new QueueExtension()); + + new Service(stack, 'my-service', { + environment, + serviceDescription, + }); + + // THEN + // Ensure creation of default queue and queue policy allowing SNS Topics to send message to the queue + expect(stack).to(haveResource('AWS::SQS::Queue', { + MessageRetentionPeriod: 1209600, + })); + + expect(stack).to(haveResource('AWS::SQS::Queue', { + RedrivePolicy: { + deadLetterTargetArn: { + 'Fn::GetAtt': [ + 'EventsDeadLetterQueue404572C7', + 'Arn', + ], + }, + maxReceiveCount: 3, + }, + })); + + // Ensure the task role is given permissions to consume messages from the queue + expect(stack).to(haveResource('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [ + { + Action: [ + 'sqs:ReceiveMessage', + 'sqs:ChangeMessageVisibility', + 'sqs:GetQueueUrl', + 'sqs:DeleteMessage', + 'sqs:GetQueueAttributes', + ], + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + // Ensure there are no SNS Subscriptions created + expect(stack).to(countResources('AWS::SNS::Subscription', 0)); + + // Ensure that the queue URL has been correctly appended to the environment variables + expect(stack).to(haveResource('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Cpu: 256, + Environment: [ + { + Name: 'PORT', + Value: '80', + }, + { + Name: 'MY-SERVICE_QUEUE_URI', + Value: { + Ref: 'EventsQueueB96EB0D2', + }, + }, + ], + Image: 'nathanpeck/name', + Essential: true, + Memory: 512, + Name: 'app', + PortMappings: [ + { + ContainerPort: 80, + Protocol: 'tcp', + }, + ], + Ulimits: [ + { + HardLimit: 1024000, + Name: 'nofile', + SoftLimit: 1024000, + }, + ], + }, + ], + })); + + test.done(); + }, + + 'should be able to subscribe default events queue created by the extension to given topics'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + const environment = new Environment(stack, 'production'); + const serviceDescription = new ServiceDescription(); + + serviceDescription.add(new Container({ + cpu: 256, + memoryMiB: 512, + trafficPort: 80, + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + environment: { + PORT: '80', + }, + })); + + // WHEN + const topicSubscription1 = new TopicSubscription({ + topic: new sns.Topic(stack, 'topic1'), + }); + const topicSubscription2 = new TopicSubscription({ + topic: new sns.Topic(stack, 'topic2'), + }); + serviceDescription.add(new QueueExtension({ + subscriptions: [topicSubscription1, topicSubscription2], + })); + + new Service(stack, 'my-service', { + environment, + serviceDescription, + }); + + // THEN + // Ensure creation of default queue and queue policy allowing SNS Topics to send message to the queue + expect(stack).to(haveResource('AWS::SQS::Queue', { + MessageRetentionPeriod: 1209600, + })); + + expect(stack).to(haveResource('AWS::SQS::Queue', { + RedrivePolicy: { + deadLetterTargetArn: { + 'Fn::GetAtt': [ + 'EventsDeadLetterQueue404572C7', + 'Arn', + ], + }, + maxReceiveCount: 3, + }, + })); + + expect(stack).to(haveResource('AWS::SQS::QueuePolicy', { + PolicyDocument: { + Statement: [ + { + Action: 'sqs:SendMessage', + Condition: { + ArnEquals: { + 'aws:SourceArn': { + Ref: 'topic152D84A37', + }, + }, + }, + Effect: 'Allow', + Principal: { + Service: 'sns.amazonaws.com', + }, + Resource: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + }, + { + Action: 'sqs:SendMessage', + Condition: { + ArnEquals: { + 'aws:SourceArn': { + Ref: 'topic2A4FB547F', + }, + }, + }, + Effect: 'Allow', + Principal: { + Service: 'sns.amazonaws.com', + }, + Resource: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + // Ensure the task role is given permissions to consume messages from the queue + expect(stack).to(haveResource('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [ + { + Action: [ + 'sqs:ReceiveMessage', + 'sqs:ChangeMessageVisibility', + 'sqs:GetQueueUrl', + 'sqs:DeleteMessage', + 'sqs:GetQueueAttributes', + ], + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + // Ensure SNS Subscriptions for given topics + expect(stack).to(haveResource('AWS::SNS::Subscription', { + Protocol: 'sqs', + TopicArn: { + Ref: 'topic152D84A37', + }, + Endpoint: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + })); + + expect(stack).to(haveResource('AWS::SNS::Subscription', { + Protocol: 'sqs', + TopicArn: { + Ref: 'topic2A4FB547F', + }, + Endpoint: { + 'Fn::GetAtt': [ + 'EventsQueueB96EB0D2', + 'Arn', + ], + }, + })); + + // Ensure that the queue URL has been correctly appended to the environment variables + expect(stack).to(haveResource('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Cpu: 256, + Environment: [ + { + Name: 'PORT', + Value: '80', + }, + { + Name: 'MY-SERVICE_QUEUE_URI', + Value: { + Ref: 'EventsQueueB96EB0D2', + }, + }, + ], + Image: 'nathanpeck/name', + Essential: true, + Memory: 512, + Name: 'app', + PortMappings: [ + { + ContainerPort: 80, + Protocol: 'tcp', + }, + ], + Ulimits: [ + { + HardLimit: 1024000, + Name: 'nofile', + SoftLimit: 1024000, + }, + ], + }, + ], + })); + + test.done(); + }, + + 'should be able to subscribe user-provided queue to given topics'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const environment = new Environment(stack, 'production'); + const serviceDescription = new ServiceDescription(); + + serviceDescription.add(new Container({ + cpu: 256, + memoryMiB: 512, + trafficPort: 80, + image: ecs.ContainerImage.fromRegistry('nathanpeck/name'), + })); + + const topicSubscription1 = new TopicSubscription({ + topic: new sns.Topic(stack, 'topic1'), + queue: new sqs.Queue(stack, 'myQueue'), + }); + const topicSubscription2 = new TopicSubscription({ + topic: new sns.Topic(stack, 'topic2'), + }); + serviceDescription.add(new QueueExtension({ + subscriptions: [topicSubscription1, topicSubscription2], + eventsQueue: new sqs.Queue(stack, 'defQueue'), + })); + + new Service(stack, 'my-service', { + environment, + serviceDescription, + }); + + // THEN + // Ensure queue policy allows SNS Topics to send message to the queue + expect(stack).to(haveResource('AWS::SQS::QueuePolicy', { + PolicyDocument: { + Statement: [ + { + Action: 'sqs:SendMessage', + Condition: { + ArnEquals: { + 'aws:SourceArn': { + Ref: 'topic152D84A37', + }, + }, + }, + Effect: 'Allow', + Principal: { + Service: 'sns.amazonaws.com', + }, + Resource: { + 'Fn::GetAtt': [ + 'myQueue4FDFF71C', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + expect(stack).to(haveResource('AWS::SQS::QueuePolicy', { + PolicyDocument: { + Statement: [ + { + Action: 'sqs:SendMessage', + Condition: { + ArnEquals: { + 'aws:SourceArn': { + Ref: 'topic2A4FB547F', + }, + }, + }, + Effect: 'Allow', + Principal: { + Service: 'sns.amazonaws.com', + }, + Resource: { + 'Fn::GetAtt': [ + 'defQueue1F91A65B', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + // Ensure the task role is given permissions to consume messages from the queue + expect(stack).to(haveResource('AWS::IAM::Policy', { + PolicyDocument: { + Statement: [ + { + Action: [ + 'sqs:ReceiveMessage', + 'sqs:ChangeMessageVisibility', + 'sqs:GetQueueUrl', + 'sqs:DeleteMessage', + 'sqs:GetQueueAttributes', + ], + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': [ + 'defQueue1F91A65B', + 'Arn', + ], + }, + }, + { + Action: [ + 'sqs:ReceiveMessage', + 'sqs:ChangeMessageVisibility', + 'sqs:GetQueueUrl', + 'sqs:DeleteMessage', + 'sqs:GetQueueAttributes', + ], + Effect: 'Allow', + Resource: { + 'Fn::GetAtt': [ + 'myQueue4FDFF71C', + 'Arn', + ], + }, + }, + ], + Version: '2012-10-17', + }, + })); + + // Ensure SNS Subscriptions for given topics + expect(stack).to(haveResource('AWS::SNS::Subscription', { + Protocol: 'sqs', + TopicArn: { + Ref: 'topic152D84A37', + }, + Endpoint: { + 'Fn::GetAtt': [ + 'myQueue4FDFF71C', + 'Arn', + ], + }, + })); + + expect(stack).to(haveResource('AWS::SNS::Subscription', { + Protocol: 'sqs', + TopicArn: { + Ref: 'topic2A4FB547F', + }, + Endpoint: { + 'Fn::GetAtt': [ + 'defQueue1F91A65B', + 'Arn', + ], + }, + })); + + // Ensure that the queue URL has been correctly added to the environment variables + expect(stack).to(haveResource('AWS::ECS::TaskDefinition', { + ContainerDefinitions: [ + { + Cpu: 256, + Environment: [ + { + Name: 'MY-SERVICE_QUEUE_URI', + Value: { + Ref: 'defQueue1F91A65B', + }, + }, + ], + Image: 'nathanpeck/name', + Essential: true, + Memory: 512, + Name: 'app', + PortMappings: [ + { + ContainerPort: 80, + Protocol: 'tcp', + }, + ], + Ulimits: [ + { + HardLimit: 1024000, + Name: 'nofile', + SoftLimit: 1024000, + }, + ], + }, + ], + })); + + test.done(); + }, +}; \ No newline at end of file From 349361d0399c05e21c5c4c5a2b69edfc6774c94f Mon Sep 17 00:00:00 2001 From: Douglas Naphas Date: Wed, 1 Sep 2021 18:10:46 -0400 Subject: [PATCH 08/10] docs(aws-ecr-assets): Correct un-closed parenthetical expression (#16172) Closes #16171. The expression is missing a right parentheses, and it is just as clear anyway as a new sentence. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-ecr-assets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-ecr-assets/README.md b/packages/@aws-cdk/aws-ecr-assets/README.md index 2414dc57c084e..f5993097418ac 100644 --- a/packages/@aws-cdk/aws-ecr-assets/README.md +++ b/packages/@aws-cdk/aws-ecr-assets/README.md @@ -46,7 +46,7 @@ interpreted. The recommended setting for Docker image assets is old projects) then `IgnoreMode.DOCKER` is the default and you don't need to configure it on the asset itself. -Use `asset.imageUri` to reference the image (it includes both the ECR image URL +Use `asset.imageUri` to reference the image. It includes both the ECR image URL and tag. You can optionally pass build args to the `docker build` command by specifying From 2c1eb08ad174ba56c4f2a0d807a0cb039534d1a9 Mon Sep 17 00:00:00 2001 From: Markus Lindqvist Date: Thu, 2 Sep 2021 01:52:19 +0300 Subject: [PATCH 09/10] docs(pipelines): Fix documentation regarding rolePolicyStatements of CodeBuildStep (#16294) fix(pipelines): Fix documentation regarding rolePolicyStatements of CodeBuildStep ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/pipelines/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/pipelines/README.md b/packages/@aws-cdk/pipelines/README.md index bab41842c2316..a63f1eab4d7c4 100644 --- a/packages/@aws-cdk/pipelines/README.md +++ b/packages/@aws-cdk/pipelines/README.md @@ -575,7 +575,7 @@ new CodeBuildStep('Synth', { securityGroups: [mySecurityGroup], // Additional policy statements for the execution role - rolePolicy: [ + rolePolicyStatements: [ new iam.PolicyStatement({ /* ... */ }), ], }); From 39eaa986e8327df96ab9a6d39a531e10b15f7542 Mon Sep 17 00:00:00 2001 From: Nick Lynch Date: Thu, 2 Sep 2021 11:18:33 +0100 Subject: [PATCH 10/10] chore: fix construct import for ecs-service-extensions --- .../ecs-service-extensions/lib/extensions/queue.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts index d43b587d6326e..073e83076f7e8 100644 --- a/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts +++ b/packages/@aws-cdk-containers/ecs-service-extensions/lib/extensions/queue.ts @@ -3,14 +3,11 @@ import * as sns from '@aws-cdk/aws-sns'; import * as subscription from '@aws-cdk/aws-sns-subscriptions'; import * as sqs from '@aws-cdk/aws-sqs'; import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; import { Service } from '../service'; import { Container } from './container'; import { ContainerMutatingHook, ServiceExtension } from './extension-interfaces'; -// Keep this import separate from other imports to reduce chance for merge conflicts with v2-main -// eslint-disable-next-line no-duplicate-imports, import/order -import { Construct } from '@aws-cdk/core'; - /** * An interface that will be implemented by all the resources that can be subscribed to. */ @@ -209,4 +206,4 @@ export class QueueExtension extends ServiceExtension { public get eventsQueue() : sqs.IQueue { return this._eventsQueue; } -} \ No newline at end of file +}