├── .eslintrc.json ├── .gitattributes ├── .github ├── pull_request_template.md └── workflows │ ├── auto-approve.yml │ ├── build.yml │ ├── pull-request-lint.yml │ ├── release.yml │ └── upgrade-main.yml ├── .gitignore ├── .gitpod.yml ├── .mergify.yml ├── .npmignore ├── .projen ├── deps.json ├── files.json └── tasks.json ├── .projenrc.js ├── API.md ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── custom-resource-handler ├── remote-outputs.py └── remote-parameters.py ├── images ├── remote-param-1.svg ├── remote-param-2.svg └── remote-param-3.svg ├── package.json ├── src ├── index.ts └── integ.default.ts ├── test ├── __snapshots__ │ └── integ.main.test.ts.snap ├── integ.main.test.ts └── main.test.ts ├── tsconfig.dev.json ├── version.json └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | // ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | { 3 | "env": { 4 | "jest": true, 5 | "node": true 6 | }, 7 | "root": true, 8 | "plugins": [ 9 | "@typescript-eslint", 10 | "import" 11 | ], 12 | "parser": "@typescript-eslint/parser", 13 | "parserOptions": { 14 | "ecmaVersion": 2018, 15 | "sourceType": "module", 16 | "project": "./tsconfig.dev.json" 17 | }, 18 | "extends": [ 19 | "plugin:import/typescript" 20 | ], 21 | "settings": { 22 | "import/parsers": { 23 | "@typescript-eslint/parser": [ 24 | ".ts", 25 | ".tsx" 26 | ] 27 | }, 28 | "import/resolver": { 29 | "node": {}, 30 | "typescript": { 31 | "project": "./tsconfig.dev.json", 32 | "alwaysTryTypes": true 33 | } 34 | } 35 | }, 36 | "ignorePatterns": [ 37 | "*.js", 38 | "*.d.ts", 39 | "node_modules/", 40 | "*.generated.ts", 41 | "coverage", 42 | "!.projenrc.js" 43 | ], 44 | "rules": { 45 | "indent": [ 46 | "off" 47 | ], 48 | "@typescript-eslint/indent": [ 49 | "error", 50 | 2 51 | ], 52 | "quotes": [ 53 | "error", 54 | "single", 55 | { 56 | "avoidEscape": true 57 | } 58 | ], 59 | "comma-dangle": [ 60 | "error", 61 | "always-multiline" 62 | ], 63 | "comma-spacing": [ 64 | "error", 65 | { 66 | "before": false, 67 | "after": true 68 | } 69 | ], 70 | "no-multi-spaces": [ 71 | "error", 72 | { 73 | "ignoreEOLComments": false 74 | } 75 | ], 76 | "array-bracket-spacing": [ 77 | "error", 78 | "never" 79 | ], 80 | "array-bracket-newline": [ 81 | "error", 82 | "consistent" 83 | ], 84 | "object-curly-spacing": [ 85 | "error", 86 | "always" 87 | ], 88 | "object-curly-newline": [ 89 | "error", 90 | { 91 | "multiline": true, 92 | "consistent": true 93 | } 94 | ], 95 | "object-property-newline": [ 96 | "error", 97 | { 98 | "allowAllPropertiesOnSameLine": true 99 | } 100 | ], 101 | "keyword-spacing": [ 102 | "error" 103 | ], 104 | "brace-style": [ 105 | "error", 106 | "1tbs", 107 | { 108 | "allowSingleLine": true 109 | } 110 | ], 111 | "space-before-blocks": [ 112 | "error" 113 | ], 114 | "curly": [ 115 | "error", 116 | "multi-line", 117 | "consistent" 118 | ], 119 | "@typescript-eslint/member-delimiter-style": [ 120 | "error" 121 | ], 122 | "semi": [ 123 | "error", 124 | "always" 125 | ], 126 | "max-len": [ 127 | "error", 128 | { 129 | "code": 150, 130 | "ignoreUrls": true, 131 | "ignoreStrings": true, 132 | "ignoreTemplateLiterals": true, 133 | "ignoreComments": true, 134 | "ignoreRegExpLiterals": true 135 | } 136 | ], 137 | "quote-props": [ 138 | "error", 139 | "consistent-as-needed" 140 | ], 141 | "@typescript-eslint/no-require-imports": [ 142 | "error" 143 | ], 144 | "import/no-extraneous-dependencies": [ 145 | "error", 146 | { 147 | "devDependencies": [ 148 | "**/test/**", 149 | "**/build-tools/**" 150 | ], 151 | "optionalDependencies": false, 152 | "peerDependencies": true 153 | } 154 | ], 155 | "import/no-unresolved": [ 156 | "error" 157 | ], 158 | "import/order": [ 159 | "warn", 160 | { 161 | "groups": [ 162 | "builtin", 163 | "external" 164 | ], 165 | "alphabetize": { 166 | "order": "asc", 167 | "caseInsensitive": true 168 | } 169 | } 170 | ], 171 | "import/no-duplicates": [ 172 | "error" 173 | ], 174 | "no-shadow": [ 175 | "off" 176 | ], 177 | "@typescript-eslint/no-shadow": [ 178 | "error" 179 | ], 180 | "key-spacing": [ 181 | "error" 182 | ], 183 | "no-multiple-empty-lines": [ 184 | "error" 185 | ], 186 | "@typescript-eslint/no-floating-promises": [ 187 | "error" 188 | ], 189 | "no-return-await": [ 190 | "off" 191 | ], 192 | "@typescript-eslint/return-await": [ 193 | "error" 194 | ], 195 | "no-trailing-spaces": [ 196 | "error" 197 | ], 198 | "dot-notation": [ 199 | "error" 200 | ], 201 | "no-bitwise": [ 202 | "error" 203 | ], 204 | "@typescript-eslint/member-ordering": [ 205 | "error", 206 | { 207 | "default": [ 208 | "public-static-field", 209 | "public-static-method", 210 | "protected-static-field", 211 | "protected-static-method", 212 | "private-static-field", 213 | "private-static-method", 214 | "field", 215 | "constructor", 216 | "method" 217 | ] 218 | } 219 | ] 220 | }, 221 | "overrides": [ 222 | { 223 | "files": [ 224 | ".projenrc.js" 225 | ], 226 | "rules": { 227 | "@typescript-eslint/no-require-imports": "off", 228 | "import/no-extraneous-dependencies": "off" 229 | } 230 | } 231 | ] 232 | } 233 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | *.snap linguist-generated 4 | /.eslintrc.json linguist-generated 5 | /.gitattributes linguist-generated 6 | /.github/pull_request_template.md linguist-generated 7 | /.github/workflows/auto-approve.yml linguist-generated 8 | /.github/workflows/build.yml linguist-generated 9 | /.github/workflows/pull-request-lint.yml linguist-generated 10 | /.github/workflows/release.yml linguist-generated 11 | /.github/workflows/upgrade-main.yml linguist-generated 12 | /.gitignore linguist-generated 13 | /.gitpod.yml linguist-generated 14 | /.mergify.yml linguist-generated 15 | /.npmignore linguist-generated 16 | /.projen/** linguist-generated 17 | /.projen/deps.json linguist-generated 18 | /.projen/files.json linguist-generated 19 | /.projen/tasks.json linguist-generated 20 | /API.md linguist-generated 21 | /LICENSE linguist-generated 22 | /package.json linguist-generated 23 | /tsconfig.dev.json linguist-generated 24 | /yarn.lock linguist-generated -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Fixes # -------------------------------------------------------------------------------- /.github/workflows/auto-approve.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | name: auto-approve 4 | on: 5 | pull_request_target: 6 | types: 7 | - labeled 8 | - opened 9 | - synchronize 10 | - reopened 11 | - ready_for_review 12 | jobs: 13 | approve: 14 | runs-on: ubuntu-latest 15 | permissions: 16 | pull-requests: write 17 | if: contains(github.event.pull_request.labels.*.name, 'auto-approve') && (github.event.pull_request.user.login == 'pahud' || github.event.pull_request.user.login == 'cdk-automation') 18 | steps: 19 | - uses: hmarr/auto-approve-action@v2.2.1 20 | with: 21 | github-token: ${{ secrets.GITHUB_TOKEN }} 22 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | name: build 4 | on: 5 | pull_request: {} 6 | workflow_dispatch: {} 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | contents: write 12 | outputs: 13 | self_mutation_happened: ${{ steps.self_mutation.outputs.self_mutation_happened }} 14 | env: 15 | CI: "true" 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | with: 20 | ref: ${{ github.event.pull_request.head.ref }} 21 | repository: ${{ github.event.pull_request.head.repo.full_name }} 22 | - name: Setup Node.js 23 | uses: actions/setup-node@v4 24 | with: 25 | node-version: 18.x 26 | - name: Install dependencies 27 | run: yarn install --check-files 28 | - name: build 29 | run: npx projen build 30 | - name: Find mutations 31 | id: self_mutation 32 | run: |- 33 | git add . 34 | git diff --staged --patch --exit-code > .repo.patch || echo "self_mutation_happened=true" >> $GITHUB_OUTPUT 35 | working-directory: ./ 36 | - name: Upload patch 37 | if: steps.self_mutation.outputs.self_mutation_happened 38 | uses: actions/upload-artifact@v4 39 | with: 40 | name: .repo.patch 41 | path: .repo.patch 42 | overwrite: true 43 | - name: Fail build on mutation 44 | if: steps.self_mutation.outputs.self_mutation_happened 45 | run: |- 46 | echo "::error::Files were changed during build (see build log). If this was triggered from a fork, you will need to update your branch." 47 | cat .repo.patch 48 | exit 1 49 | - name: Backup artifact permissions 50 | run: cd dist && getfacl -R . > permissions-backup.acl 51 | continue-on-error: true 52 | - name: Upload artifact 53 | uses: actions/upload-artifact@v4 54 | with: 55 | name: build-artifact 56 | path: dist 57 | overwrite: true 58 | self-mutation: 59 | needs: build 60 | runs-on: ubuntu-latest 61 | permissions: 62 | contents: write 63 | if: always() && needs.build.outputs.self_mutation_happened && !(github.event.pull_request.head.repo.full_name != github.repository) 64 | steps: 65 | - name: Checkout 66 | uses: actions/checkout@v4 67 | with: 68 | token: ${{ secrets.PROJEN_GITHUB_TOKEN }} 69 | ref: ${{ github.event.pull_request.head.ref }} 70 | repository: ${{ github.event.pull_request.head.repo.full_name }} 71 | - name: Download patch 72 | uses: actions/download-artifact@v4 73 | with: 74 | name: .repo.patch 75 | path: ${{ runner.temp }} 76 | - name: Apply patch 77 | run: '[ -s ${{ runner.temp }}/.repo.patch ] && git apply ${{ runner.temp }}/.repo.patch || echo "Empty patch. Skipping."' 78 | - name: Set git identity 79 | run: |- 80 | git config user.name "github-actions" 81 | git config user.email "github-actions@github.com" 82 | - name: Push changes 83 | env: 84 | PULL_REQUEST_REF: ${{ github.event.pull_request.head.ref }} 85 | run: |- 86 | git add . 87 | git commit -s -m "chore: self mutation" 88 | git push origin HEAD:$PULL_REQUEST_REF 89 | package-js: 90 | needs: build 91 | runs-on: ubuntu-latest 92 | permissions: {} 93 | if: "! needs.build.outputs.self_mutation_happened" 94 | steps: 95 | - uses: actions/setup-node@v4 96 | with: 97 | node-version: 18.x 98 | - name: Download build artifacts 99 | uses: actions/download-artifact@v4 100 | with: 101 | name: build-artifact 102 | path: dist 103 | - name: Restore build artifact permissions 104 | run: cd dist && setfacl --restore=permissions-backup.acl 105 | continue-on-error: true 106 | - name: Prepare Repository 107 | run: mv dist .repo 108 | - name: Install Dependencies 109 | run: cd .repo && yarn install --check-files --frozen-lockfile 110 | - name: Create js artifact 111 | run: cd .repo && npx projen package:js 112 | - name: Collect js Artifact 113 | run: mv .repo/dist dist 114 | package-python: 115 | needs: build 116 | runs-on: ubuntu-latest 117 | permissions: {} 118 | if: "! needs.build.outputs.self_mutation_happened" 119 | steps: 120 | - uses: actions/setup-node@v4 121 | with: 122 | node-version: 18.x 123 | - uses: actions/setup-python@v5 124 | with: 125 | python-version: 3.x 126 | - name: Download build artifacts 127 | uses: actions/download-artifact@v4 128 | with: 129 | name: build-artifact 130 | path: dist 131 | - name: Restore build artifact permissions 132 | run: cd dist && setfacl --restore=permissions-backup.acl 133 | continue-on-error: true 134 | - name: Prepare Repository 135 | run: mv dist .repo 136 | - name: Install Dependencies 137 | run: cd .repo && yarn install --check-files --frozen-lockfile 138 | - name: Create python artifact 139 | run: cd .repo && npx projen package:python 140 | - name: Collect python Artifact 141 | run: mv .repo/dist dist 142 | -------------------------------------------------------------------------------- /.github/workflows/pull-request-lint.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | name: pull-request-lint 4 | on: 5 | pull_request_target: 6 | types: 7 | - labeled 8 | - opened 9 | - synchronize 10 | - reopened 11 | - ready_for_review 12 | - edited 13 | jobs: 14 | validate: 15 | name: Validate PR title 16 | runs-on: ubuntu-latest 17 | permissions: 18 | pull-requests: write 19 | steps: 20 | - uses: amannn/action-semantic-pull-request@v5.4.0 21 | env: 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | with: 24 | types: |- 25 | feat 26 | fix 27 | chore 28 | requireScope: false 29 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | name: release 4 | on: 5 | push: 6 | branches: 7 | - main 8 | workflow_dispatch: {} 9 | jobs: 10 | release: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | outputs: 15 | latest_commit: ${{ steps.git_remote.outputs.latest_commit }} 16 | tag_exists: ${{ steps.check_tag_exists.outputs.exists }} 17 | env: 18 | CI: "true" 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | with: 23 | fetch-depth: 0 24 | - name: Set git identity 25 | run: |- 26 | git config user.name "github-actions" 27 | git config user.email "github-actions@github.com" 28 | - name: Setup Node.js 29 | uses: actions/setup-node@v4 30 | with: 31 | node-version: 18.x 32 | - name: Install dependencies 33 | run: yarn install --check-files --frozen-lockfile 34 | - name: release 35 | run: npx projen release 36 | - name: Check if version has already been tagged 37 | id: check_tag_exists 38 | run: |- 39 | TAG=$(cat dist/dist/releasetag.txt) 40 | ([ ! -z "$TAG" ] && git ls-remote -q --exit-code --tags origin $TAG && (echo "exists=true" >> $GITHUB_OUTPUT)) || (echo "exists=false" >> $GITHUB_OUTPUT) 41 | cat $GITHUB_OUTPUT 42 | - name: Check for new commits 43 | id: git_remote 44 | run: |- 45 | echo "latest_commit=$(git ls-remote origin -h ${{ github.ref }} | cut -f1)" >> $GITHUB_OUTPUT 46 | cat $GITHUB_OUTPUT 47 | - name: Backup artifact permissions 48 | if: ${{ steps.git_remote.outputs.latest_commit == github.sha }} 49 | run: cd dist && getfacl -R . > permissions-backup.acl 50 | continue-on-error: true 51 | - name: Upload artifact 52 | if: ${{ steps.git_remote.outputs.latest_commit == github.sha }} 53 | uses: actions/upload-artifact@v4 54 | with: 55 | name: build-artifact 56 | path: dist 57 | overwrite: true 58 | release_github: 59 | name: Publish to GitHub Releases 60 | needs: 61 | - release 62 | - release_npm 63 | - release_pypi 64 | runs-on: ubuntu-latest 65 | permissions: 66 | contents: write 67 | if: needs.release.outputs.tag_exists != 'true' && needs.release.outputs.latest_commit == github.sha 68 | steps: 69 | - uses: actions/setup-node@v4 70 | with: 71 | node-version: 18.x 72 | - name: Download build artifacts 73 | uses: actions/download-artifact@v4 74 | with: 75 | name: build-artifact 76 | path: dist 77 | - name: Restore build artifact permissions 78 | run: cd dist && setfacl --restore=permissions-backup.acl 79 | continue-on-error: true 80 | - name: Prepare Repository 81 | run: mv dist .repo 82 | - name: Collect GitHub Metadata 83 | run: mv .repo/dist dist 84 | - name: Release 85 | env: 86 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 87 | GITHUB_REPOSITORY: ${{ github.repository }} 88 | GITHUB_REF: ${{ github.sha }} 89 | run: errout=$(mktemp); gh release create $(cat dist/releasetag.txt) -R $GITHUB_REPOSITORY -F dist/changelog.md -t $(cat dist/releasetag.txt) --target $GITHUB_REF 2> $errout && true; exitcode=$?; if [ $exitcode -ne 0 ] && ! grep -q "Release.tag_name already exists" $errout; then cat $errout; exit $exitcode; fi 90 | release_npm: 91 | name: Publish to npm 92 | needs: release 93 | runs-on: ubuntu-latest 94 | permissions: 95 | id-token: write 96 | contents: read 97 | if: needs.release.outputs.tag_exists != 'true' && needs.release.outputs.latest_commit == github.sha 98 | steps: 99 | - uses: actions/setup-node@v4 100 | with: 101 | node-version: 18.x 102 | - name: Download build artifacts 103 | uses: actions/download-artifact@v4 104 | with: 105 | name: build-artifact 106 | path: dist 107 | - name: Restore build artifact permissions 108 | run: cd dist && setfacl --restore=permissions-backup.acl 109 | continue-on-error: true 110 | - name: Prepare Repository 111 | run: mv dist .repo 112 | - name: Install Dependencies 113 | run: cd .repo && yarn install --check-files --frozen-lockfile 114 | - name: Create js artifact 115 | run: cd .repo && npx projen package:js 116 | - name: Collect js Artifact 117 | run: mv .repo/dist dist 118 | - name: Release 119 | env: 120 | NPM_DIST_TAG: latest 121 | NPM_REGISTRY: registry.npmjs.org 122 | NPM_CONFIG_PROVENANCE: "true" 123 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 124 | run: npx -p publib@latest publib-npm 125 | release_pypi: 126 | name: Publish to PyPI 127 | needs: release 128 | runs-on: ubuntu-latest 129 | permissions: 130 | contents: read 131 | if: needs.release.outputs.tag_exists != 'true' && needs.release.outputs.latest_commit == github.sha 132 | steps: 133 | - uses: actions/setup-node@v4 134 | with: 135 | node-version: 18.x 136 | - uses: actions/setup-python@v5 137 | with: 138 | python-version: 3.x 139 | - name: Download build artifacts 140 | uses: actions/download-artifact@v4 141 | with: 142 | name: build-artifact 143 | path: dist 144 | - name: Restore build artifact permissions 145 | run: cd dist && setfacl --restore=permissions-backup.acl 146 | continue-on-error: true 147 | - name: Prepare Repository 148 | run: mv dist .repo 149 | - name: Install Dependencies 150 | run: cd .repo && yarn install --check-files --frozen-lockfile 151 | - name: Create python artifact 152 | run: cd .repo && npx projen package:python 153 | - name: Collect python Artifact 154 | run: mv .repo/dist dist 155 | - name: Release 156 | env: 157 | TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} 158 | TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} 159 | run: npx -p publib@latest publib-pypi 160 | -------------------------------------------------------------------------------- /.github/workflows/upgrade-main.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | name: upgrade-main 4 | on: 5 | workflow_dispatch: {} 6 | schedule: 7 | - cron: 0 0 * * * 8 | jobs: 9 | upgrade: 10 | name: Upgrade 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: read 14 | outputs: 15 | patch_created: ${{ steps.create_patch.outputs.patch_created }} 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | with: 20 | ref: main 21 | - name: Setup Node.js 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: 18.x 25 | - name: Install dependencies 26 | run: yarn install --check-files --frozen-lockfile 27 | - name: Upgrade dependencies 28 | run: npx projen upgrade 29 | - name: Find mutations 30 | id: create_patch 31 | run: |- 32 | git add . 33 | git diff --staged --patch --exit-code > .repo.patch || echo "patch_created=true" >> $GITHUB_OUTPUT 34 | working-directory: ./ 35 | - name: Upload patch 36 | if: steps.create_patch.outputs.patch_created 37 | uses: actions/upload-artifact@v4 38 | with: 39 | name: .repo.patch 40 | path: .repo.patch 41 | overwrite: true 42 | pr: 43 | name: Create Pull Request 44 | needs: upgrade 45 | runs-on: ubuntu-latest 46 | permissions: 47 | contents: read 48 | if: ${{ needs.upgrade.outputs.patch_created }} 49 | steps: 50 | - name: Checkout 51 | uses: actions/checkout@v4 52 | with: 53 | ref: main 54 | - name: Download patch 55 | uses: actions/download-artifact@v4 56 | with: 57 | name: .repo.patch 58 | path: ${{ runner.temp }} 59 | - name: Apply patch 60 | run: '[ -s ${{ runner.temp }}/.repo.patch ] && git apply ${{ runner.temp }}/.repo.patch || echo "Empty patch. Skipping."' 61 | - name: Set git identity 62 | run: |- 63 | git config user.name "github-actions" 64 | git config user.email "github-actions@github.com" 65 | - name: Create Pull Request 66 | id: create-pr 67 | uses: peter-evans/create-pull-request@v6 68 | with: 69 | token: ${{ secrets.PROJEN_GITHUB_TOKEN }} 70 | commit-message: |- 71 | chore(deps): upgrade dependencies 72 | 73 | Upgrades project dependencies. See details in [workflow run]. 74 | 75 | [Workflow Run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} 76 | 77 | ------ 78 | 79 | *Automatically created by projen via the "upgrade-main" workflow* 80 | branch: github-actions/upgrade-main 81 | title: "chore(deps): upgrade dependencies" 82 | labels: auto-approve,auto-merge 83 | body: |- 84 | Upgrades project dependencies. See details in [workflow run]. 85 | 86 | [Workflow Run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} 87 | 88 | ------ 89 | 90 | *Automatically created by projen via the "upgrade-main" workflow* 91 | author: github-actions 92 | committer: github-actions 93 | signoff: true 94 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | !/.gitattributes 3 | !/.projen/tasks.json 4 | !/.projen/deps.json 5 | !/.projen/files.json 6 | !/.github/workflows/pull-request-lint.yml 7 | !/.github/workflows/auto-approve.yml 8 | !/package.json 9 | !/LICENSE 10 | !/.npmignore 11 | logs 12 | *.log 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | lerna-debug.log* 17 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | lib-cov 23 | coverage 24 | *.lcov 25 | .nyc_output 26 | build/Release 27 | node_modules/ 28 | jspm_packages/ 29 | *.tsbuildinfo 30 | .eslintcache 31 | *.tgz 32 | .yarn-integrity 33 | .cache 34 | /test-reports/ 35 | junit.xml 36 | /coverage/ 37 | !/.github/workflows/build.yml 38 | /dist/changelog.md 39 | /dist/version.txt 40 | !/.github/workflows/release.yml 41 | !/.mergify.yml 42 | !/.github/workflows/upgrade-main.yml 43 | !/.github/pull_request_template.md 44 | !/test/ 45 | !/tsconfig.dev.json 46 | !/src/ 47 | /lib 48 | /dist/ 49 | !/.eslintrc.json 50 | .jsii 51 | tsconfig.json 52 | !/API.md 53 | !/.gitpod.yml 54 | cdk.out 55 | cdk.context.json 56 | yarn-error.log 57 | !/.projenrc.js 58 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | image: public.ecr.aws/pahudnet/gitpod-workspace:latest 4 | tasks: 5 | - command: npx projen upgrade 6 | init: yarn gitpod:prebuild 7 | github: 8 | prebuilds: 9 | addCheck: true 10 | addBadge: true 11 | addLabel: true 12 | branches: true 13 | pullRequests: true 14 | pullRequestsFromForks: true 15 | vscode: 16 | extensions: 17 | - dbaeumer.vscode-eslint 18 | - ms-azuretools.vscode-docker 19 | - AmazonWebServices.aws-toolkit-vscode 20 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | 3 | queue_rules: 4 | - name: default 5 | update_method: merge 6 | conditions: 7 | - "#approved-reviews-by>=1" 8 | - -label~=(do-not-merge) 9 | - status-success=build 10 | - status-success=package-js 11 | - status-success=package-python 12 | pull_request_rules: 13 | - name: Automatic merge on approval and successful build 14 | actions: 15 | delete_head_branch: {} 16 | queue: 17 | method: squash 18 | name: default 19 | commit_message_template: |- 20 | {{ title }} (#{{ number }}) 21 | 22 | {{ body }} 23 | conditions: 24 | - "#approved-reviews-by>=1" 25 | - -label~=(do-not-merge) 26 | - status-success=build 27 | - status-success=package-js 28 | - status-success=package-python 29 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | /.projen/ 3 | /test-reports/ 4 | junit.xml 5 | /coverage/ 6 | permissions-backup.acl 7 | /dist/changelog.md 8 | /dist/version.txt 9 | /.mergify.yml 10 | /test/ 11 | /tsconfig.dev.json 12 | /src/ 13 | !/lib/ 14 | !/lib/**/*.js 15 | !/lib/**/*.d.ts 16 | dist 17 | /tsconfig.json 18 | /.github/ 19 | /.vscode/ 20 | /.idea/ 21 | /.projenrc.js 22 | tsconfig.tsbuildinfo 23 | /.eslintrc.json 24 | !.jsii 25 | cdk.out 26 | cdk.context.json 27 | yarn-error.log 28 | /.gitattributes 29 | -------------------------------------------------------------------------------- /.projen/deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "name": "@types/jest", 5 | "version": "^27", 6 | "type": "build" 7 | }, 8 | { 9 | "name": "@types/node", 10 | "version": "^16 <= 16.18.78", 11 | "type": "build" 12 | }, 13 | { 14 | "name": "@typescript-eslint/eslint-plugin", 15 | "version": "^7", 16 | "type": "build" 17 | }, 18 | { 19 | "name": "@typescript-eslint/parser", 20 | "version": "^7", 21 | "type": "build" 22 | }, 23 | { 24 | "name": "eslint-import-resolver-typescript", 25 | "type": "build" 26 | }, 27 | { 28 | "name": "eslint-plugin-import", 29 | "type": "build" 30 | }, 31 | { 32 | "name": "eslint", 33 | "version": "^8", 34 | "type": "build" 35 | }, 36 | { 37 | "name": "jest-junit", 38 | "version": "^15", 39 | "type": "build" 40 | }, 41 | { 42 | "name": "jest", 43 | "version": "^27", 44 | "type": "build" 45 | }, 46 | { 47 | "name": "jsii-diff", 48 | "type": "build" 49 | }, 50 | { 51 | "name": "jsii-docgen", 52 | "type": "build" 53 | }, 54 | { 55 | "name": "jsii-pacmak", 56 | "type": "build" 57 | }, 58 | { 59 | "name": "jsii-rosetta", 60 | "version": "1.x", 61 | "type": "build" 62 | }, 63 | { 64 | "name": "jsii", 65 | "version": "1.x", 66 | "type": "build" 67 | }, 68 | { 69 | "name": "projen", 70 | "type": "build" 71 | }, 72 | { 73 | "name": "standard-version", 74 | "version": "^9", 75 | "type": "build" 76 | }, 77 | { 78 | "name": "ts-jest", 79 | "version": "^27", 80 | "type": "build" 81 | }, 82 | { 83 | "name": "typescript", 84 | "type": "build" 85 | }, 86 | { 87 | "name": "@types/babel__traverse", 88 | "version": "7.18.2", 89 | "type": "override" 90 | }, 91 | { 92 | "name": "@types/prettier", 93 | "version": "2.6.0", 94 | "type": "override" 95 | }, 96 | { 97 | "name": "aws-cdk-lib", 98 | "version": "^2.85.0", 99 | "type": "peer" 100 | }, 101 | { 102 | "name": "constructs", 103 | "version": "^10.0.5", 104 | "type": "peer" 105 | } 106 | ], 107 | "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." 108 | } 109 | -------------------------------------------------------------------------------- /.projen/files.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | ".eslintrc.json", 4 | ".gitattributes", 5 | ".github/pull_request_template.md", 6 | ".github/workflows/auto-approve.yml", 7 | ".github/workflows/build.yml", 8 | ".github/workflows/pull-request-lint.yml", 9 | ".github/workflows/release.yml", 10 | ".github/workflows/upgrade-main.yml", 11 | ".gitignore", 12 | ".gitpod.yml", 13 | ".mergify.yml", 14 | ".projen/deps.json", 15 | ".projen/files.json", 16 | ".projen/tasks.json", 17 | "LICENSE", 18 | "tsconfig.dev.json" 19 | ], 20 | "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." 21 | } 22 | -------------------------------------------------------------------------------- /.projen/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "build": { 4 | "name": "build", 5 | "description": "Full release build", 6 | "steps": [ 7 | { 8 | "spawn": "default" 9 | }, 10 | { 11 | "spawn": "pre-compile" 12 | }, 13 | { 14 | "spawn": "compile" 15 | }, 16 | { 17 | "spawn": "post-compile" 18 | }, 19 | { 20 | "spawn": "test" 21 | }, 22 | { 23 | "spawn": "package" 24 | } 25 | ] 26 | }, 27 | "bump": { 28 | "name": "bump", 29 | "description": "Bumps version based on latest git tag and generates a changelog entry", 30 | "env": { 31 | "OUTFILE": "package.json", 32 | "CHANGELOG": "dist/changelog.md", 33 | "BUMPFILE": "dist/version.txt", 34 | "RELEASETAG": "dist/releasetag.txt", 35 | "RELEASE_TAG_PREFIX": "" 36 | }, 37 | "steps": [ 38 | { 39 | "builtin": "release/bump-version" 40 | } 41 | ], 42 | "condition": "! git log --oneline -1 | grep -q \"chore(release):\"" 43 | }, 44 | "clobber": { 45 | "name": "clobber", 46 | "description": "hard resets to HEAD of origin and cleans the local repo", 47 | "env": { 48 | "BRANCH": "$(git branch --show-current)" 49 | }, 50 | "steps": [ 51 | { 52 | "exec": "git checkout -b scratch", 53 | "name": "save current HEAD in \"scratch\" branch" 54 | }, 55 | { 56 | "exec": "git checkout $BRANCH" 57 | }, 58 | { 59 | "exec": "git fetch origin", 60 | "name": "fetch latest changes from origin" 61 | }, 62 | { 63 | "exec": "git reset --hard origin/$BRANCH", 64 | "name": "hard reset to origin commit" 65 | }, 66 | { 67 | "exec": "git clean -fdx", 68 | "name": "clean all untracked files" 69 | }, 70 | { 71 | "say": "ready to rock! (unpushed commits are under the \"scratch\" branch)" 72 | } 73 | ], 74 | "condition": "git diff --exit-code > /dev/null" 75 | }, 76 | "compat": { 77 | "name": "compat", 78 | "description": "Perform API compatibility check against latest version", 79 | "steps": [ 80 | { 81 | "exec": "jsii-diff npm:$(node -p \"require('./package.json').name\") -k --ignore-file .compatignore || (echo \"\nUNEXPECTED BREAKING CHANGES: add keys such as 'removed:constructs.Node.of' to .compatignore to skip.\n\" && exit 1)" 82 | } 83 | ] 84 | }, 85 | "compile": { 86 | "name": "compile", 87 | "description": "Only compile", 88 | "steps": [ 89 | { 90 | "exec": "jsii --silence-warnings=reserved-word" 91 | } 92 | ] 93 | }, 94 | "default": { 95 | "name": "default", 96 | "description": "Synthesize project files", 97 | "steps": [ 98 | { 99 | "exec": "node .projenrc.js" 100 | } 101 | ] 102 | }, 103 | "docgen": { 104 | "name": "docgen", 105 | "description": "Generate API.md from .jsii manifest", 106 | "steps": [ 107 | { 108 | "exec": "jsii-docgen -o API.md" 109 | } 110 | ] 111 | }, 112 | "eject": { 113 | "name": "eject", 114 | "description": "Remove projen from the project", 115 | "env": { 116 | "PROJEN_EJECTING": "true" 117 | }, 118 | "steps": [ 119 | { 120 | "spawn": "default" 121 | } 122 | ] 123 | }, 124 | "eslint": { 125 | "name": "eslint", 126 | "description": "Runs eslint against the codebase", 127 | "steps": [ 128 | { 129 | "exec": "eslint --ext .ts,.tsx --fix --no-error-on-unmatched-pattern $@ src test build-tools .projenrc.js", 130 | "receiveArgs": true 131 | } 132 | ] 133 | }, 134 | "gitpod:prebuild": { 135 | "name": "gitpod:prebuild", 136 | "description": "Prebuild setup for Gitpod", 137 | "steps": [ 138 | { 139 | "exec": "yarn install --frozen-lockfile --check-files" 140 | }, 141 | { 142 | "exec": "npx projen compile" 143 | } 144 | ] 145 | }, 146 | "install": { 147 | "name": "install", 148 | "description": "Install project dependencies and update lockfile (non-frozen)", 149 | "steps": [ 150 | { 151 | "exec": "yarn install --check-files" 152 | } 153 | ] 154 | }, 155 | "install:ci": { 156 | "name": "install:ci", 157 | "description": "Install project dependencies using frozen lockfile", 158 | "steps": [ 159 | { 160 | "exec": "yarn install --check-files --frozen-lockfile" 161 | } 162 | ] 163 | }, 164 | "package": { 165 | "name": "package", 166 | "description": "Creates the distribution package", 167 | "steps": [ 168 | { 169 | "exec": "if [ ! -z ${CI} ]; then rsync -a . .repo --exclude .git --exclude node_modules && rm -rf dist && mv .repo dist; else npx projen package-all; fi" 170 | } 171 | ] 172 | }, 173 | "package-all": { 174 | "name": "package-all", 175 | "description": "Packages artifacts for all target languages", 176 | "steps": [ 177 | { 178 | "spawn": "package:js" 179 | }, 180 | { 181 | "spawn": "package:python" 182 | } 183 | ] 184 | }, 185 | "package:js": { 186 | "name": "package:js", 187 | "description": "Create js language bindings", 188 | "steps": [ 189 | { 190 | "exec": "jsii-pacmak -v --target js" 191 | } 192 | ] 193 | }, 194 | "package:python": { 195 | "name": "package:python", 196 | "description": "Create python language bindings", 197 | "steps": [ 198 | { 199 | "exec": "jsii-pacmak -v --target python" 200 | } 201 | ] 202 | }, 203 | "post-compile": { 204 | "name": "post-compile", 205 | "description": "Runs after successful compilation", 206 | "steps": [ 207 | { 208 | "spawn": "docgen" 209 | } 210 | ] 211 | }, 212 | "post-upgrade": { 213 | "name": "post-upgrade", 214 | "description": "Runs after upgrading dependencies" 215 | }, 216 | "pre-compile": { 217 | "name": "pre-compile", 218 | "description": "Prepare the project for compilation" 219 | }, 220 | "release": { 221 | "name": "release", 222 | "description": "Prepare a release from \"main\" branch", 223 | "env": { 224 | "RELEASE": "true", 225 | "MAJOR": "2" 226 | }, 227 | "steps": [ 228 | { 229 | "exec": "rm -fr dist" 230 | }, 231 | { 232 | "spawn": "bump" 233 | }, 234 | { 235 | "spawn": "build" 236 | }, 237 | { 238 | "spawn": "unbump" 239 | }, 240 | { 241 | "exec": "git diff --ignore-space-at-eol --exit-code" 242 | } 243 | ] 244 | }, 245 | "test": { 246 | "name": "test", 247 | "description": "Run tests", 248 | "steps": [ 249 | { 250 | "exec": "jest --passWithNoTests --updateSnapshot", 251 | "receiveArgs": true 252 | }, 253 | { 254 | "spawn": "eslint" 255 | } 256 | ] 257 | }, 258 | "test:watch": { 259 | "name": "test:watch", 260 | "description": "Run jest in watch mode", 261 | "steps": [ 262 | { 263 | "exec": "jest --watch" 264 | } 265 | ] 266 | }, 267 | "unbump": { 268 | "name": "unbump", 269 | "description": "Restores version to 0.0.0", 270 | "env": { 271 | "OUTFILE": "package.json", 272 | "CHANGELOG": "dist/changelog.md", 273 | "BUMPFILE": "dist/version.txt", 274 | "RELEASETAG": "dist/releasetag.txt", 275 | "RELEASE_TAG_PREFIX": "" 276 | }, 277 | "steps": [ 278 | { 279 | "builtin": "release/reset-version" 280 | } 281 | ] 282 | }, 283 | "upgrade": { 284 | "name": "upgrade", 285 | "description": "upgrade dependencies", 286 | "env": { 287 | "CI": "0" 288 | }, 289 | "steps": [ 290 | { 291 | "exec": "npx npm-check-updates@16 --upgrade --target=minor --peer --dep=dev,peer,prod,optional --filter=eslint-import-resolver-typescript,eslint-plugin-import,jsii-diff,jsii-docgen,jsii-pacmak,projen,typescript" 292 | }, 293 | { 294 | "exec": "yarn install --check-files" 295 | }, 296 | { 297 | "exec": "yarn upgrade @types/jest @types/node @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-import-resolver-typescript eslint-plugin-import eslint jest-junit jest jsii-diff jsii-docgen jsii-pacmak jsii-rosetta jsii projen standard-version ts-jest typescript aws-cdk-lib constructs" 298 | }, 299 | { 300 | "exec": "npx projen" 301 | }, 302 | { 303 | "spawn": "post-upgrade" 304 | } 305 | ] 306 | }, 307 | "watch": { 308 | "name": "watch", 309 | "description": "Watch & compile in the background", 310 | "steps": [ 311 | { 312 | "exec": "jsii -w --silence-warnings=reserved-word" 313 | } 314 | ] 315 | } 316 | }, 317 | "env": { 318 | "PATH": "$(npx -c \"node --print process.env.PATH\")" 319 | }, 320 | "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." 321 | } 322 | -------------------------------------------------------------------------------- /.projenrc.js: -------------------------------------------------------------------------------- 1 | const { awscdk, DevEnvironmentDockerImage, Gitpod } = require('projen'); 2 | 3 | const PROJECT_NAME = 'cdk-remote-stack'; 4 | const PROJECT_DESCRIPTION = 'Get outputs and AWS SSM parameters from cross-region AWS CloudFormation stacks'; 5 | const AUTOMATION_TOKEN = 'AUTOMATION_GITHUB_TOKEN'; 6 | 7 | const project = new awscdk.AwsCdkConstructLibrary({ 8 | authorName: 'Pahud Hsieh', 9 | authorEmail: 'pahudnet@gmail.com', 10 | name: PROJECT_NAME, 11 | description: PROJECT_DESCRIPTION, 12 | repository: 'https://github.com/pahud/cdk-remote-stack.git', 13 | authorUrl: 'https://twitter.com/pahudnet', 14 | keywords: [ 15 | 'aws', 16 | 'remote', 17 | 'cross-region', 18 | 'cross-stack', 19 | 'cross-account', 20 | ], 21 | /** 22 | * we default release the main branch(cdkv2) with major version 2. 23 | */ 24 | majorVersion: 2, 25 | defaultReleaseBranch: 'main', 26 | /** 27 | * we also release the cdkv1 branch with major version 1. 28 | */ 29 | // releaseBranches: { 30 | // cdkv1: { npmDistTag: 'cdkv1', majorVersion: 1 }, 31 | // }, 32 | depsUpgradeOptions: { 33 | ignoreProjen: false, 34 | workflowOptions: { 35 | labels: ['auto-approve', 'auto-merge'], 36 | secret: AUTOMATION_TOKEN, 37 | }, 38 | }, 39 | autoApproveOptions: { 40 | secret: 'GITHUB_TOKEN', 41 | allowedUsernames: ['pahud', 'cdk-automation'], 42 | }, 43 | defaultReleaseBranch: 'main', 44 | catalog: { 45 | twitter: 'pahudnet', 46 | announce: false, 47 | }, 48 | cdkVersion: '2.85.0', 49 | python: { 50 | distName: 'cdk-remote-stack', 51 | module: 'cdk_remote_stack', 52 | }, 53 | }); 54 | 55 | const gitpodPrebuild = project.addTask('gitpod:prebuild', { 56 | description: 'Prebuild setup for Gitpod', 57 | }); 58 | // install and compile only, do not test or package. 59 | gitpodPrebuild.exec('yarn install --frozen-lockfile --check-files'); 60 | gitpodPrebuild.exec('npx projen compile'); 61 | 62 | let gitpod = new Gitpod(project, { 63 | dockerImage: DevEnvironmentDockerImage.fromImage('public.ecr.aws/pahudnet/gitpod-workspace:latest'), 64 | prebuilds: { 65 | addCheck: true, 66 | addBadge: true, 67 | addLabel: true, 68 | branches: true, 69 | pullRequests: true, 70 | pullRequestsFromForks: true, 71 | }, 72 | }); 73 | 74 | gitpod.addCustomTask({ 75 | init: 'yarn gitpod:prebuild', 76 | // always upgrade after init 77 | command: 'npx projen upgrade', 78 | }); 79 | 80 | gitpod.addVscodeExtensions( 81 | 'dbaeumer.vscode-eslint', 82 | 'ms-azuretools.vscode-docker', 83 | 'AmazonWebServices.aws-toolkit-vscode', 84 | ); 85 | 86 | const common_exclude = ['cdk.out', 'cdk.context.json', 'yarn-error.log']; 87 | project.npmignore.exclude(...common_exclude); 88 | project.gitignore.exclude(...common_exclude); 89 | 90 | project.synth(); 91 | -------------------------------------------------------------------------------- /API.md: -------------------------------------------------------------------------------- 1 | # API Reference 2 | 3 | **Classes** 4 | 5 | Name|Description 6 | ----|----------- 7 | [RemoteOutputs](#cdk-remote-stack-remoteoutputs)|Represents the RemoteOutputs of the remote CDK stack. 8 | [RemoteParameters](#cdk-remote-stack-remoteparameters)|Represents the RemoteParameters of the remote CDK stack. 9 | 10 | 11 | **Structs** 12 | 13 | Name|Description 14 | ----|----------- 15 | [RemoteOutputsProps](#cdk-remote-stack-remoteoutputsprops)|Properties of the RemoteOutputs. 16 | [RemoteParametersProps](#cdk-remote-stack-remoteparametersprops)|Properties of the RemoteParameters. 17 | 18 | 19 | 20 | ## class RemoteOutputs 21 | 22 | Represents the RemoteOutputs of the remote CDK stack. 23 | 24 | __Implements__: [IConstruct](#constructs-iconstruct), [IDependable](#constructs-idependable) 25 | __Extends__: [Construct](#constructs-construct) 26 | 27 | ### Initializer 28 | 29 | 30 | 31 | 32 | ```ts 33 | new RemoteOutputs(scope: Construct, id: string, props: RemoteOutputsProps) 34 | ``` 35 | 36 | * **scope** ([Construct](#constructs-construct)) *No description* 37 | * **id** (string) *No description* 38 | * **props** ([RemoteOutputsProps](#cdk-remote-stack-remoteoutputsprops)) *No description* 39 | * **stack** ([Stack](#aws-cdk-lib-stack)) The remote CDK stack to get the outputs from. 40 | * **alwaysUpdate** (boolean) Indicate whether always update the custom resource to get the new stack output. __*Default*__: true 41 | * **timeout** ([Duration](#aws-cdk-lib-duration)) timeout for custom resource handler. __*Default*__: no timeout specified. 42 | 43 | 44 | 45 | ### Properties 46 | 47 | 48 | Name | Type | Description 49 | -----|------|------------- 50 | **outputs** | [CustomResource](#aws-cdk-lib-customresource) | The outputs from the remote stack. 51 | 52 | ### Methods 53 | 54 | 55 | #### get(key) 56 | 57 | Get the attribute value from the outputs. 58 | 59 | ```ts 60 | get(key: string): string 61 | ``` 62 | 63 | * **key** (string) output key. 64 | 65 | __Returns__: 66 | * string 67 | 68 | 69 | 70 | ## class RemoteParameters 71 | 72 | Represents the RemoteParameters of the remote CDK stack. 73 | 74 | __Implements__: [IConstruct](#constructs-iconstruct), [IDependable](#constructs-idependable) 75 | __Extends__: [Construct](#constructs-construct) 76 | 77 | ### Initializer 78 | 79 | 80 | 81 | 82 | ```ts 83 | new RemoteParameters(scope: Construct, id: string, props: RemoteParametersProps) 84 | ``` 85 | 86 | * **scope** ([Construct](#constructs-construct)) *No description* 87 | * **id** (string) *No description* 88 | * **props** ([RemoteParametersProps](#cdk-remote-stack-remoteparametersprops)) *No description* 89 | * **path** (string) The parameter path. 90 | * **region** (string) The region code of the remote stack. 91 | * **alwaysUpdate** (boolean) Indicate whether always update the custom resource to get the new stack output. __*Default*__: true 92 | * **role** ([aws_iam.IRole](#aws-cdk-lib-aws-iam-irole)) The assumed role used to get remote parameters. __*Optional*__ 93 | * **timeout** ([Duration](#aws-cdk-lib-duration)) timeout for custom resource handler. __*Default*__: no timeout specified. 94 | 95 | 96 | 97 | ### Properties 98 | 99 | 100 | Name | Type | Description 101 | -----|------|------------- 102 | **parameters** | [CustomResource](#aws-cdk-lib-customresource) | The parameters in the SSM parameter store for the remote stack. 103 | 104 | ### Methods 105 | 106 | 107 | #### get(key) 108 | 109 | Get the parameter. 110 | 111 | ```ts 112 | get(key: string): string 113 | ``` 114 | 115 | * **key** (string) output key. 116 | 117 | __Returns__: 118 | * string 119 | 120 | 121 | 122 | ## struct RemoteOutputsProps 123 | 124 | 125 | Properties of the RemoteOutputs. 126 | 127 | 128 | 129 | Name | Type | Description 130 | -----|------|------------- 131 | **stack** | [Stack](#aws-cdk-lib-stack) | The remote CDK stack to get the outputs from. 132 | **alwaysUpdate**? | boolean | Indicate whether always update the custom resource to get the new stack output.
__*Default*__: true 133 | **timeout**? | [Duration](#aws-cdk-lib-duration) | timeout for custom resource handler.
__*Default*__: no timeout specified. 134 | 135 | 136 | 137 | ## struct RemoteParametersProps 138 | 139 | 140 | Properties of the RemoteParameters. 141 | 142 | 143 | 144 | Name | Type | Description 145 | -----|------|------------- 146 | **path** | string | The parameter path. 147 | **region** | string | The region code of the remote stack. 148 | **alwaysUpdate**? | boolean | Indicate whether always update the custom resource to get the new stack output.
__*Default*__: true 149 | **role**? | [aws_iam.IRole](#aws-cdk-lib-aws-iam-irole) | The assumed role used to get remote parameters.
__*Optional*__ 150 | **timeout**? | [Duration](#aws-cdk-lib-duration) | timeout for custom resource handler.
__*Default*__: no timeout specified. 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 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. 4 | 5 | ### [0.1.136](https://github.com/pahud/cdk-remote-stack/compare/v0.1.135...v0.1.136) (2021-02-03) 6 | 7 | ### [0.1.135](https://github.com/pahud/cdk-remote-stack/compare/v0.1.134...v0.1.135) (2021-02-02) 8 | 9 | ### [0.1.134](https://github.com/pahud/cdk-remote-stack/compare/v0.1.133...v0.1.134) (2021-02-01) 10 | 11 | ### [0.1.133](https://github.com/pahud/cdk-remote-stack/compare/v0.1.132...v0.1.133) (2021-01-12) 12 | 13 | ### [0.1.132](https://github.com/pahud/cdk-remote-stack/compare/v0.1.131...v0.1.132) (2021-01-11) 14 | 15 | ### [0.1.131](https://github.com/pahud/cdk-remote-stack/compare/v0.1.130...v0.1.131) (2021-01-10) 16 | 17 | ### [0.1.130](https://github.com/pahud/cdk-remote-stack/compare/v0.1.129...v0.1.130) (2021-01-09) 18 | 19 | ### [0.1.129](https://github.com/pahud/cdk-remote-stack/compare/v0.1.128...v0.1.129) (2021-01-08) 20 | 21 | ### [0.1.128](https://github.com/pahud/cdk-remote-stack/compare/v0.1.127...v0.1.128) (2021-01-07) 22 | 23 | ### [0.1.127](https://github.com/pahud/cdk-remote-stack/compare/v0.1.126...v0.1.127) (2021-01-06) 24 | 25 | ### [0.1.126](https://github.com/pahud/cdk-remote-stack/compare/v0.1.125...v0.1.126) (2021-01-05) 26 | 27 | ### [0.1.125](https://github.com/pahud/cdk-remote-stack/compare/v0.1.124...v0.1.125) (2021-01-04) 28 | 29 | ### [0.1.124](https://github.com/pahud/cdk-remote-stack/compare/v0.1.123...v0.1.124) (2021-01-04) 30 | 31 | ### [0.1.123](https://github.com/pahud/cdk-remote-stack/compare/v0.1.122...v0.1.123) (2021-01-03) 32 | 33 | ### [0.1.122](https://github.com/pahud/cdk-remote-stack/compare/v0.1.121...v0.1.122) (2021-01-02) 34 | 35 | ### [0.1.121](https://github.com/pahud/cdk-remote-stack/compare/v0.1.120...v0.1.121) (2021-01-01) 36 | 37 | ### [0.1.120](https://github.com/pahud/cdk-remote-stack/compare/v0.1.119...v0.1.120) (2020-12-31) 38 | 39 | ### [0.1.119](https://github.com/pahud/cdk-remote-stack/compare/v0.1.118...v0.1.119) (2020-12-30) 40 | 41 | ### [0.1.118](https://github.com/pahud/cdk-remote-stack/compare/v0.1.117...v0.1.118) (2020-12-29) 42 | 43 | ### [0.1.117](https://github.com/pahud/cdk-remote-stack/compare/v0.1.116...v0.1.117) (2020-12-28) 44 | 45 | ### [0.1.116](https://github.com/pahud/cdk-remote-stack/compare/v0.1.115...v0.1.116) (2020-12-27) 46 | 47 | ### 0.1.115 (2020-12-21) 48 | 49 | ### 0.1.114 (2020-12-20) 50 | 51 | ### 0.1.113 (2020-12-20) 52 | 53 | ### 0.1.112 (2020-12-20) 54 | 55 | ### 0.1.111 (2020-12-19) 56 | 57 | ### 0.1.110 (2020-11-24) 58 | 59 | ### 0.1.109 (2020-11-24) 60 | 61 | ### 0.1.108 (2020-11-23) 62 | 63 | ### 0.1.107 (2020-11-22) 64 | 65 | ### 0.1.106 (2020-11-20) 66 | 67 | ### 0.1.105 (2020-11-20) 68 | 69 | ### 0.1.104 (2020-11-19) 70 | 71 | ### 0.1.103 (2020-11-18) 72 | 73 | ### 0.1.102 (2020-11-18) 74 | 75 | ### 0.1.101 (2020-11-17) 76 | 77 | ### 0.1.100 (2020-11-17) 78 | 79 | ### 0.1.99 (2020-11-16) 80 | 81 | 82 | ### Features 83 | 84 | * **core:** support always get the output from the source stack ([#120](https://github.com/pahud/cdk-remote-stack/issues/120)) ([6df8e9b](https://github.com/pahud/cdk-remote-stack/commit/6df8e9b94cd4cc3a45edc24a77cd94c69c51c284)), closes [#118](https://github.com/pahud/cdk-remote-stack/issues/118) 85 | 86 | ### 0.1.98 (2020-11-16) 87 | 88 | ### 0.1.97 (2020-11-16) 89 | 90 | ### 0.1.96 (2020-11-15) 91 | 92 | ### 0.1.95 (2020-11-14) 93 | 94 | ### 0.1.94 (2020-11-13) 95 | 96 | ### 0.1.93 (2020-11-13) 97 | 98 | ### 0.1.92 (2020-11-12) 99 | 100 | ### 0.1.91 (2020-11-12) 101 | 102 | ### 0.1.90 (2020-11-11) 103 | 104 | ### 0.1.89 (2020-11-11) 105 | 106 | ### 0.1.88 (2020-11-10) 107 | 108 | ### 0.1.87 (2020-11-10) 109 | 110 | ### 0.1.86 (2020-11-09) 111 | 112 | ### 0.1.85 (2020-11-09) 113 | 114 | ### 0.1.84 (2020-11-08) 115 | 116 | ### 0.1.83 (2020-11-07) 117 | 118 | ### 0.1.82 (2020-11-06) 119 | 120 | ### 0.1.81 (2020-11-06) 121 | 122 | ### 0.1.80 (2020-11-05) 123 | 124 | ### 0.1.79 (2020-11-04) 125 | 126 | ### 0.1.78 (2020-11-03) 127 | 128 | ### 0.1.77 (2020-11-02) 129 | 130 | ### 0.1.76 (2020-11-01) 131 | 132 | ### 0.1.75 (2020-10-31) 133 | 134 | ### 0.1.74 (2020-10-30) 135 | 136 | ### 0.1.73 (2020-10-29) 137 | 138 | ### 0.1.72 (2020-10-28) 139 | 140 | ### 0.1.71 (2020-10-27) 141 | 142 | ### 0.1.70 (2020-10-26) 143 | 144 | ### 0.1.69 (2020-10-26) 145 | 146 | ### 0.1.68 (2020-10-25) 147 | 148 | ### 0.1.67 (2020-10-24) 149 | 150 | ### 0.1.66 (2020-10-23) 151 | 152 | ### 0.1.65 (2020-10-22) 153 | 154 | ### 0.1.64 (2020-10-22) 155 | 156 | ### 0.1.63 (2020-10-22) 157 | 158 | ### 0.1.62 (2020-10-22) 159 | 160 | ### 0.1.61 (2020-10-21) 161 | 162 | ### 0.1.60 (2020-10-20) 163 | 164 | ### 0.1.59 (2020-10-19) 165 | 166 | ### 0.1.58 (2020-10-19) 167 | 168 | ### 0.1.57 (2020-10-18) 169 | 170 | ### 0.1.56 (2020-10-17) 171 | 172 | ### 0.1.55 (2020-10-16) 173 | 174 | ### 0.1.54 (2020-10-15) 175 | 176 | ### 0.1.53 (2020-10-15) 177 | 178 | ### 0.1.52 (2020-10-15) 179 | 180 | ### 0.1.51 (2020-10-14) 181 | 182 | ### 0.1.50 (2020-10-14) 183 | 184 | ### 0.1.49 (2020-10-13) 185 | 186 | ### 0.1.48 (2020-10-13) 187 | 188 | ### 0.1.47 (2020-10-12) 189 | 190 | ### 0.1.46 (2020-10-12) 191 | 192 | ### 0.1.45 (2020-10-11) 193 | 194 | ### 0.1.44 (2020-10-10) 195 | 196 | ### 0.1.43 (2020-10-09) 197 | 198 | ### 0.1.42 (2020-10-09) 199 | 200 | ### 0.1.41 (2020-10-08) 201 | 202 | ### 0.1.40 (2020-10-07) 203 | 204 | ### 0.1.39 (2020-10-07) 205 | 206 | ### 0.1.38 (2020-10-06) 207 | 208 | ### 0.1.37 (2020-10-06) 209 | 210 | ### 0.1.36 (2020-10-06) 211 | 212 | ### 0.1.35 (2020-09-30) 213 | 214 | ### 0.1.34 (2020-09-30) 215 | 216 | ### 0.1.33 (2020-09-29) 217 | 218 | ### 0.1.32 (2020-09-29) 219 | 220 | ### 0.1.31 (2020-09-29) 221 | 222 | ### 0.1.30 (2020-09-29) 223 | 224 | ### 0.1.29 (2020-09-29) 225 | 226 | ### 0.1.28 (2020-09-28) 227 | 228 | ### 0.1.27 (2020-09-28) 229 | 230 | ### 0.1.26 (2020-09-28) 231 | 232 | ### 0.1.25 (2020-09-28) 233 | 234 | ### 0.1.24 (2020-09-28) 235 | 236 | ### 0.1.23 (2020-09-27) 237 | 238 | ### 0.1.22 (2020-09-27) 239 | 240 | ### 0.1.21 (2020-09-25) 241 | 242 | ### 0.1.20 (2020-09-23) 243 | 244 | ### 0.1.19 (2020-09-22) 245 | 246 | ### 0.1.18 (2020-09-22) 247 | 248 | ### 0.1.17 (2020-09-21) 249 | 250 | ### 0.1.16 (2020-09-17) 251 | 252 | ### 0.1.15 (2020-09-17) 253 | 254 | ### 0.1.14 (2020-09-17) 255 | 256 | ### 0.1.13 (2020-09-17) 257 | 258 | ### 0.1.12 (2020-09-16) 259 | 260 | ### 0.1.11 (2020-09-16) 261 | 262 | ### 0.1.10 (2020-09-15) 263 | 264 | ### 0.1.9 (2020-09-14) 265 | 266 | ### 0.1.8 (2020-09-14) 267 | 268 | ### 0.1.7 (2020-09-11) 269 | 270 | ### 0.1.6 (2020-09-11) 271 | 272 | ### 0.1.5 (2020-09-09) 273 | 274 | ### 0.1.4 (2020-09-09) 275 | 276 | ### 0.1.3 (2020-09-09) 277 | 278 | ### 0.1.2 (2020-09-09) 279 | 280 | ### 0.1.1 (2020-09-08) 281 | 282 | ## [0.1.0](https://github.com/pahud/cdk-remote-stack/compare/v0.0.1...v0.1.0) (2020-09-08) 283 | 284 | ### 0.0.1 (2020-09-08) 285 | 286 | 287 | ### Features 288 | 289 | * **core:** initial commit ([3f8e81f](https://github.com/pahud/cdk-remote-stack/commit/3f8e81f71a8a5a26c49c1a58a2ae0aad76540318)) 290 | * **core:** initial commit ([7d61418](https://github.com/pahud/cdk-remote-stack/commit/7d61418c2ebec7dc98613a7728e80dcf7b22d422)) 291 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Security issue notifications 48 | If you discover a potential security issue in this project, please reach out to us via the author email in [package.json](./package.json). Please do **not** create a public GitHub issue. 49 | 50 | 51 | ## Licensing 52 | 53 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/cdk-remote-stack.svg)](https://badge.fury.io/js/cdk-remote-stack) 2 | [![PyPI version](https://badge.fury.io/py/cdk-remote-stack.svg)](https://badge.fury.io/py/cdk-remote-stack) 3 | [![release](https://github.com/pahud/cdk-remote-stack/actions/workflows/release.yml/badge.svg)](https://github.com/pahud/cdk-remote-stack/actions/workflows/release.yml) 4 | 5 | # cdk-remote-stack 6 | 7 | Get outputs and AWS SSM parameters from cross-region AWS CloudFormation stacks 8 | 9 | # Install 10 | 11 | Use the npm dist tag to opt in CDKv1 or CDKv2: 12 | 13 | ```sh 14 | // for CDKv2 15 | npm install cdk-remote-stack 16 | or 17 | npm install cdk-remote-stack@latest 18 | 19 | // for CDKv1 20 | npm install cdk-remote-stack@cdkv1 21 | ``` 22 | 23 | # Why 24 | 25 | Setting up cross-regional cross-stack references requires using multiple constructs from the AWS CDK construct library and is not straightforward. 26 | 27 | `cdk-remote-stack` aims to simplify the cross-regional cross-stack references to help you easily build cross-regional multi-stack AWS CDK applications. 28 | 29 | This construct library provides two main constructs: 30 | - **RemoteOutputs** - cross regional stack outputs reference. 31 | - **RemoteParameters** - cross regional/account SSM parameters reference. 32 | 33 | # RemoteOutputs 34 | 35 | `RemoteOutputs` is ideal for one stack referencing the outputs from another across different AWS regions. 36 | 37 | Let's say we have two cross-regional stacks in the same AWS CDK application: 38 | 39 | 1. **stackJP** - stack in Japan (`JP`) to create a SNS topic 40 | 2. **stackUS** - stack in United States (`US`) to get the outputs from `stackJP` and print out the SNS `TopicName` from `stackJP` outputs. 41 | 42 | ```ts 43 | import { RemoteOutputs } from 'cdk-remote-stack'; 44 | import * as cdk from 'aws-cdk-lib'; 45 | 46 | const app = new cdk.App(); 47 | 48 | const envJP = { 49 | region: 'ap-northeast-1', 50 | account: process.env.CDK_DEFAULT_ACCOUNT, 51 | }; 52 | 53 | const envUS = { 54 | region: 'us-west-2', 55 | account: process.env.CDK_DEFAULT_ACCOUNT, 56 | }; 57 | 58 | // first stack in JP 59 | const stackJP = new cdk.Stack(app, 'demo-stack-jp', { env: envJP }) 60 | 61 | new cdk.CfnOutput(stackJP, 'TopicName', { value: 'foo' }) 62 | 63 | // second stack in US 64 | const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS }) 65 | 66 | // ensure the dependency 67 | stackUS.addDependency(stackJP) 68 | 69 | // get the stackJP stack outputs from stackUS 70 | const outputs = new RemoteOutputs(stackUS, 'Outputs', { stack: stackJP }) 71 | 72 | const remoteOutputValue = outputs.get('TopicName') 73 | 74 | // the value should be exactly the same with the output value of `TopicName` 75 | new cdk.CfnOutput(stackUS, 'RemoteTopicName', { value: remoteOutputValue }) 76 | ``` 77 | 78 | At this moment, `RemoteOutputs` only supports cross-regional reference in a single AWS account. 79 | 80 | ## Always get the latest stack output 81 | 82 | By default, the `RemoteOutputs` construct will always try to get the latest output from the source stack. You may opt out by setting `alwaysUpdate` to `false` to turn this feature off. 83 | 84 | For example: 85 | ```ts 86 | const outputs = new RemoteOutputs(stackUS, 'Outputs', { 87 | stack: stackJP, 88 | alwaysUpdate: false, 89 | }) 90 | ``` 91 | 92 | # RemoteParameters 93 | 94 | [AWS Systems Manager (AWS SSM) Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) is great to store and persist parameters and allow stacks from other regons/accounts to reference. Let's dive into the two major scenarios below: 95 | 96 | ## Stacks from single account and different regions 97 | 98 | In this sample, we create two stacks from JP (`ap-northeast-1`) and US (`us-west-2`). The JP stack will produce and update parameters in its parameter store, while the US stack will consume the parameters across differnt regions with the `RemoteParameters` construct. 99 | 100 | ![](images/remote-param-1.svg) 101 | 102 | ```ts 103 | const envJP = { region: 'ap-northeast-1', account: '111111111111' }; 104 | const envUS = { region: 'us-west-2', account: '111111111111' }; 105 | 106 | // first stack in JP 107 | const producerStackName = 'demo-stack-jp'; 108 | const stackJP = new cdk.Stack(app, producerStackName, { env: envJP }); 109 | const parameterPath = `/${envJP.account}/${envJP.region}/${producerStackName}` 110 | 111 | new ssm.StringParameter(stackJP, 'foo1', { 112 | parameterName: `${parameterPath}/foo1`, 113 | stringValue: 'bar1', 114 | }); 115 | new ssm.StringParameter(stackJP, 'foo2', { 116 | parameterName: `${parameterPath}/foo2`, 117 | stringValue: 'bar2', 118 | }); 119 | new ssm.StringParameter(stackJP, 'foo3', { 120 | parameterName: `${parameterPath}/foo3`, 121 | stringValue: 'bar3', 122 | }); 123 | 124 | // second stack in US 125 | const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS }); 126 | 127 | // ensure the dependency 128 | stackUS.addDependency(stackJP); 129 | 130 | // get remote parameters by path from AWS SSM parameter store 131 | const parameters = new RemoteParameters(stackUS, 'Parameters', { 132 | path: parameterPath, 133 | region: stackJP.region, 134 | }) 135 | 136 | const foo1 = parameters.get(`${parameterPath}/foo1`); 137 | const foo2 = parameters.get(`${parameterPath}/foo2`); 138 | const foo3 = parameters.get(`${parameterPath}/foo3`); 139 | 140 | new cdk.CfnOutput(stackUS, 'foo1Output', { value: foo1 }); 141 | new cdk.CfnOutput(stackUS, 'foo2Output', { value: foo2 }); 142 | new cdk.CfnOutput(stackUS, 'foo3Output', { value: foo3 }); 143 | ``` 144 | 145 | ## Stacks from differnt accounts and different regions 146 | 147 | Similar to the use case above, but now we deploy stacks in separate accounts and regions. We will need to pass an AWS Identity and Access Management (AWS IAM) `role` to the `RemoteParameters` construct to get all the parameters from the remote environment. 148 | 149 | ![](images/remote-param-2.svg) 150 | 151 | ```ts 152 | 153 | const envJP = { region: 'ap-northeast-1', account: '111111111111' }; 154 | const envUS = { region: 'us-west-2', account: '222222222222' }; 155 | 156 | // first stack in JP 157 | const producerStackName = 'demo-stack-jp'; 158 | const stackJP = new cdk.Stack(app, producerStackName, { env: envJP }); 159 | const parameterPath = `/${envJP.account}/${envJP.region}/${producerStackName}` 160 | 161 | new ssm.StringParameter(stackJP, 'foo1', { 162 | parameterName: `${parameterPath}/foo1`, 163 | stringValue: 'bar1', 164 | }); 165 | new ssm.StringParameter(stackJP, 'foo2', { 166 | parameterName: `${parameterPath}/foo2`, 167 | stringValue: 'bar2', 168 | }); 169 | new ssm.StringParameter(stackJP, 'foo3', { 170 | parameterName: `${parameterPath}/foo3`, 171 | stringValue: 'bar3', 172 | }); 173 | 174 | // allow US account to assume this read only role to get parameters 175 | const cdkReadOnlyRole = new iam.Role(stackJP, 'readOnlyRole', { 176 | assumedBy: new iam.AccountPrincipal(envUS.account), 177 | roleName: PhysicalName.GENERATE_IF_NEEDED, 178 | managedPolicies: [ iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMReadOnlyAccess')], 179 | }) 180 | 181 | // second stack in US 182 | const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS }); 183 | 184 | // ensure the dependency 185 | stackUS.addDependency(stackJP); 186 | 187 | // get remote parameters by path from AWS SSM parameter store 188 | const parameters = new RemoteParameters(stackUS, 'Parameters', { 189 | path: parameterPath, 190 | region: stackJP.region, 191 | // assume this role for cross-account parameters 192 | role: iam.Role.fromRoleArn(stackUS, 'readOnlyRole', cdkReadOnlyRole.roleArn), 193 | }) 194 | 195 | const foo1 = parameters.get(`${parameterPath}/foo1`); 196 | const foo2 = parameters.get(`${parameterPath}/foo2`); 197 | const foo3 = parameters.get(`${parameterPath}/foo3`); 198 | 199 | new cdk.CfnOutput(stackUS, 'foo1Output', { value: foo1 }); 200 | new cdk.CfnOutput(stackUS, 'foo2Output', { value: foo2 }); 201 | new cdk.CfnOutput(stackUS, 'foo3Output', { value: foo3 }); 202 | ``` 203 | 204 | ## Dedicated account for a centralized parameter store 205 | 206 | The parameters are stored in a centralized account/region and previously provisioned as a source-of-truth configuration store. All other stacks from different accounts/regions are consuming the parameters from the central configuration store. 207 | 208 | This scenario is pretty much like #2. The difference is that there's a dedicated account for centralized configuration store being shared with all other accounts. 209 | 210 | ![](images/remote-param-3.svg) 211 | 212 | You will need create `RemoteParameters` for all the consuming stacks like: 213 | ```ts 214 | // for StackUS 215 | new RemoteParameters(stackUS, 'Parameters', { 216 | path: parameterPath, 217 | region: 'eu-central-1' 218 | // assume this role for cross-account parameters 219 | role: iam.Role.fromRoleArn(stackUS, 'readOnlyRole', sharedReadOnlyRoleArn), 220 | }) 221 | 222 | // for StackJP 223 | new RemoteParameters(stackJP, 'Parameters', { 224 | path: parameterPath, 225 | region: 'eu-central-1' 226 | // assume this role for cross-account parameters 227 | role: iam.Role.fromRoleArn(stackJP, 'readOnlyRole', sharedReadOnlyRoleArn), 228 | }) 229 | ``` 230 | 231 | ## Tools for multi-account deployment 232 | You will need to install and bootstrap your target accounts with AWS CDK 1.108.0 or later, so you can deploy stacks from different accounts. It [adds support](https://github.com/aws/aws-cdk/pull/14874) for cross-account lookups. Alternatively, install [cdk-assume-role-credential-plugin](https://github.com/aws-samples/cdk-assume-role-credential-plugin). Read this [blog post](https://aws.amazon.com/tw/blogs/devops/cdk-credential-plugin/) to setup this plugin. 233 | 234 | ## Limitations 235 | 1. At this moment, the `RemoteParameters` construct only supports the `String` data type from parameter store. 236 | 2. Maximum number of parameters is `100`. Will make it configurable in the future if required. 237 | 238 | # Contributing 239 | 240 | See [CONTRIBUTING](CONTRIBUTING.md) for more information. 241 | 242 | # License 243 | This code is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file. 244 | -------------------------------------------------------------------------------- /custom-resource-handler/remote-outputs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import boto3 4 | import json 5 | 6 | 7 | def on_event(event, context): 8 | print(event) 9 | request_type = event["RequestType"] 10 | if request_type == "Create": 11 | return on_create(event) 12 | if request_type == "Update": 13 | return on_update(event) 14 | if request_type == "Delete": 15 | return on_delete(event) 16 | raise Exception("Invalid request type: %s" % request_type) 17 | 18 | 19 | def on_create(event): 20 | props = event["ResourceProperties"] 21 | print("create new resource with props %s" % props) 22 | stack_name = props["stackName"] 23 | region_name = props["regionName"] 24 | client = boto3.client("cloudformation", region_name=region_name) 25 | response = client.describe_stacks(StackName=stack_name) 26 | print(response["Stacks"][0].get("Outputs")) 27 | outputs = response["Stacks"][0].get("Outputs") 28 | output = {} 29 | for o in outputs: 30 | output[o.get("OutputKey")] = o.get("OutputValue") 31 | print(output) 32 | 33 | # add your create code here... 34 | physical_id = stack_name 35 | return {"PhysicalResourceId": physical_id, "Data": output} 36 | 37 | 38 | def on_update(event): 39 | physical_id = event["PhysicalResourceId"] 40 | props = event["ResourceProperties"] 41 | print("update resource %s with props %s" % (physical_id, props)) 42 | stack_name = props["stackName"] 43 | region_name = props["regionName"] 44 | print("on_update describing %s from %s", stack_name, region_name) 45 | client = boto3.client("cloudformation", region_name=region_name) 46 | response = client.describe_stacks(StackName=stack_name) 47 | print(response["Stacks"][0].get("Outputs")) 48 | outputs = response["Stacks"][0].get("Outputs") 49 | output = {} 50 | for o in outputs: 51 | output[o.get("OutputKey")] = o.get("OutputValue") 52 | print(output) 53 | 54 | # add your create code here... 55 | physical_id = stack_name 56 | return {"PhysicalResourceId": physical_id, "Data": output} 57 | 58 | 59 | def on_delete(event): 60 | physical_id = event["PhysicalResourceId"] 61 | print("delete resource %s" % physical_id) 62 | # ... 63 | -------------------------------------------------------------------------------- /custom-resource-handler/remote-parameters.py: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env python3 3 | 4 | import boto3 5 | from boto3.session import Session 6 | 7 | def get_ssm_client(region_name, role_arn=None, session_name=None): 8 | if role_arn: 9 | sts_client = boto3.client('sts') 10 | response = sts_client.assume_role(RoleArn=role_arn, RoleSessionName=session_name) 11 | session = Session(aws_access_key_id=response['Credentials']['AccessKeyId'], 12 | aws_secret_access_key=response['Credentials']['SecretAccessKey'], 13 | aws_session_token=response['Credentials']['SessionToken']) 14 | client = session.client("ssm", region_name=region_name) 15 | else: 16 | client = boto3.client("ssm", region_name=region_name) 17 | return client 18 | 19 | def get_parameters(region_name, path, role_arn=None, session_name=None): 20 | client = get_ssm_client(region_name, role_arn, session_name) 21 | paginator = client.get_paginator('get_parameters_by_path') 22 | response_iterator = paginator.paginate( 23 | Path=path, 24 | Recursive=True, 25 | WithDecryption=True, 26 | PaginationConfig={ 27 | 'MaxItems': 100, 28 | 'PageSize': 10, 29 | } 30 | ) 31 | result = [] 32 | for x in response_iterator: 33 | result += x["Parameters"] 34 | output = {} 35 | for x in result: 36 | output[x["Name"]] = x["Value"] 37 | return output 38 | 39 | def on_event(event, context): 40 | print(event) 41 | request_type = event.get("RequestType") 42 | if request_type == "Create": 43 | return on_create(event) 44 | if request_type == "Update": 45 | return on_update(event) 46 | if request_type == "Delete": 47 | return on_delete(event) 48 | raise Exception("Invalid request type: %s" % request_type) 49 | 50 | 51 | def on_create(event): 52 | props = event.get("ResourceProperties") 53 | print("create new resource with props %s" % props) 54 | stack_name = props.get("stackName") 55 | region_name = props.get("regionName") 56 | path = props.get("parameterPath") 57 | role = props.get("role") 58 | output = get_parameters(region_name, path, role_arn=role, session_name=stack_name) 59 | return {"Data": output} 60 | 61 | 62 | def on_update(event): 63 | physical_id = event.get("PhysicalResourceId") 64 | props = event.get("ResourceProperties") 65 | print("update resource %s with props %s" % (physical_id, props)) 66 | stack_name = props.get("stackName") 67 | region_name = props.get("regionName") 68 | print("on_update in progress") 69 | path = props.get("parameterPath") 70 | role = props.get("role") 71 | output = get_parameters(region_name, path, role_arn=role, session_name=stack_name) 72 | return {"PhysicalResourceId": physical_id, "Data": output} 73 | 74 | 75 | def on_delete(event): 76 | physical_id = event.get("PhysicalResourceId") 77 | print("delete resource %s" % physical_id) -------------------------------------------------------------------------------- /images/remote-param-1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
ap-northeast-1
ap-northeast-1
us-west-2
us-west-2
StackJP
StackJP
StackUS
StackUS
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
RemoteParameters
RemoteParameters
GetParametersByPath
GetParametersByPath
Construct
Construct
Construct
Construct
reference
reference
reference
reference
Same Account
Different Regions
Same Account...
Viewer does not support full SVG 1.1
-------------------------------------------------------------------------------- /images/remote-param-2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
ap-northeast-1
ap-northeast-1
us-west-2
us-west-2
StackJP
StackJP
StackUS
StackUS
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
RemoteParameters
RemoteParameters
GetParametersByPath
with the Assumed Role
GetParametersByPath...
Construct
Construct
Construct
Construct
reference
reference
reference
reference
Different Accounts
Different Regions
Different Accounts...
Read-Only Role
Read-Only Role
Viewer does not support full SVG 1.1
-------------------------------------------------------------------------------- /images/remote-param-3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
ap-northeast-1
ap-northeast-1
us-west-2
us-west-2
StackJP
StackJP
StackUS
StackUS
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
Parameter
RemoteParameters
RemoteParame...
GetParametersByPath
with the Assumed Role
GetParametersByPath...
Read-Only Role
Read-Only Role
RemoteParameters
RemoteParame...
GetParametersByPath
with the Assumed Role
GetParametersByPath...
eu-central-1
eu-central-1
Viewer does not support full SVG 1.1
-------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cdk-remote-stack", 3 | "description": "Get outputs and AWS SSM parameters from cross-region AWS CloudFormation stacks", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/pahud/cdk-remote-stack.git" 7 | }, 8 | "scripts": { 9 | "build": "npx projen build", 10 | "bump": "npx projen bump", 11 | "clobber": "npx projen clobber", 12 | "compat": "npx projen compat", 13 | "compile": "npx projen compile", 14 | "default": "npx projen default", 15 | "docgen": "npx projen docgen", 16 | "eject": "npx projen eject", 17 | "eslint": "npx projen eslint", 18 | "gitpod:prebuild": "npx projen gitpod:prebuild", 19 | "package": "npx projen package", 20 | "package-all": "npx projen package-all", 21 | "package:js": "npx projen package:js", 22 | "package:python": "npx projen package:python", 23 | "post-compile": "npx projen post-compile", 24 | "post-upgrade": "npx projen post-upgrade", 25 | "pre-compile": "npx projen pre-compile", 26 | "release": "npx projen release", 27 | "test": "npx projen test", 28 | "test:watch": "npx projen test:watch", 29 | "unbump": "npx projen unbump", 30 | "upgrade": "npx projen upgrade", 31 | "watch": "npx projen watch", 32 | "projen": "npx projen" 33 | }, 34 | "author": { 35 | "name": "Pahud Hsieh", 36 | "email": "pahudnet@gmail.com", 37 | "url": "https://twitter.com/pahudnet", 38 | "organization": false 39 | }, 40 | "devDependencies": { 41 | "@types/jest": "^27", 42 | "@types/node": "^16 <= 16.18.78", 43 | "@typescript-eslint/eslint-plugin": "^7", 44 | "@typescript-eslint/parser": "^7", 45 | "aws-cdk-lib": "2.85.0", 46 | "constructs": "10.0.5", 47 | "eslint": "^8", 48 | "eslint-import-resolver-typescript": "^2.7.1", 49 | "eslint-plugin-import": "^2.29.1", 50 | "jest": "^27", 51 | "jest-junit": "^15", 52 | "jsii": "1.x", 53 | "jsii-diff": "^1.101.0", 54 | "jsii-docgen": "^1.8.110", 55 | "jsii-pacmak": "^1.101.0", 56 | "jsii-rosetta": "1.x", 57 | "projen": "^0.84.5", 58 | "standard-version": "^9", 59 | "ts-jest": "^27", 60 | "typescript": "^4.9.5" 61 | }, 62 | "peerDependencies": { 63 | "aws-cdk-lib": "^2.85.0", 64 | "constructs": "^10.0.5" 65 | }, 66 | "resolutions": { 67 | "@types/babel__traverse": "7.18.2", 68 | "@types/prettier": "2.6.0" 69 | }, 70 | "keywords": [ 71 | "aws", 72 | "cdk", 73 | "cross-account", 74 | "cross-region", 75 | "cross-stack", 76 | "remote" 77 | ], 78 | "main": "lib/index.js", 79 | "license": "Apache-2.0", 80 | "publishConfig": { 81 | "access": "public" 82 | }, 83 | "version": "0.0.0", 84 | "jest": { 85 | "coverageProvider": "v8", 86 | "testMatch": [ 87 | "/@(src|test)/**/?(*.)+(spec|test).ts?(x)", 88 | "/@(src|test)/**/__tests__/**/*.ts?(x)" 89 | ], 90 | "clearMocks": true, 91 | "collectCoverage": true, 92 | "coverageReporters": [ 93 | "json", 94 | "lcov", 95 | "clover", 96 | "cobertura", 97 | "text" 98 | ], 99 | "coverageDirectory": "coverage", 100 | "coveragePathIgnorePatterns": [ 101 | "/node_modules/" 102 | ], 103 | "testPathIgnorePatterns": [ 104 | "/node_modules/" 105 | ], 106 | "watchPathIgnorePatterns": [ 107 | "/node_modules/" 108 | ], 109 | "reporters": [ 110 | "default", 111 | [ 112 | "jest-junit", 113 | { 114 | "outputDirectory": "test-reports" 115 | } 116 | ] 117 | ], 118 | "preset": "ts-jest", 119 | "globals": { 120 | "ts-jest": { 121 | "tsconfig": "tsconfig.dev.json" 122 | } 123 | } 124 | }, 125 | "types": "lib/index.d.ts", 126 | "stability": "stable", 127 | "jsii": { 128 | "outdir": "dist", 129 | "targets": { 130 | "python": { 131 | "distName": "cdk-remote-stack", 132 | "module": "cdk_remote_stack" 133 | } 134 | }, 135 | "tsc": { 136 | "outDir": "lib", 137 | "rootDir": "src" 138 | } 139 | }, 140 | "awscdkio": { 141 | "twitter": "pahudnet", 142 | "announce": false 143 | }, 144 | "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." 145 | } 146 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import { 3 | Stack, CustomResource, Duration, 4 | aws_iam as iam, 5 | aws_lambda as lambda, 6 | aws_logs as logs, 7 | custom_resources as cr, 8 | } from 'aws-cdk-lib'; 9 | import { Construct } from 'constructs'; 10 | 11 | /** 12 | * Properties of the RemoteOutputs 13 | */ 14 | export interface RemoteOutputsProps { 15 | /** 16 | * The remote CDK stack to get the outputs from. 17 | */ 18 | readonly stack: Stack; 19 | /** 20 | * Indicate whether always update the custom resource to get the new stack output 21 | * @default true 22 | */ 23 | readonly alwaysUpdate?: boolean; 24 | /** 25 | * timeout for custom resource handler 26 | * @default - no timeout specified. 27 | */ 28 | readonly timeout?: Duration; 29 | } 30 | 31 | /** 32 | * Represents the RemoteOutputs of the remote CDK stack 33 | */ 34 | export class RemoteOutputs extends Construct { 35 | /** 36 | * The outputs from the remote stack. 37 | */ 38 | readonly outputs: CustomResource; 39 | 40 | constructor(scope: Construct, id: string, props: RemoteOutputsProps) { 41 | super(scope, id); 42 | 43 | const onEvent = new lambda.Function(this, 'MyHandler', { 44 | runtime: lambda.Runtime.PYTHON_3_9, 45 | code: lambda.Code.fromAsset(path.join(__dirname, '../custom-resource-handler')), 46 | handler: 'remote-outputs.on_event', 47 | timeout: props.timeout, 48 | }); 49 | 50 | const myProvider = new cr.Provider(this, 'MyProvider', { 51 | onEventHandler: onEvent, 52 | logRetention: logs.RetentionDays.ONE_DAY, 53 | }); 54 | 55 | onEvent.addToRolePolicy(new iam.PolicyStatement({ 56 | actions: ['cloudformation:DescribeStacks'], 57 | resources: ['*'], 58 | })); 59 | 60 | this.outputs = new CustomResource(this, 'RemoteOutputs', { 61 | serviceToken: myProvider.serviceToken, 62 | properties: { 63 | stackName: props.stack.stackName, 64 | regionName: Stack.of(props.stack).region, 65 | randomString: props.alwaysUpdate == false ? undefined : randomString(), 66 | }, 67 | }); 68 | } 69 | 70 | /** 71 | * Get the attribute value from the outputs. 72 | * @param key output key 73 | */ 74 | public get(key: string) { 75 | return this.outputs.getAttString(key); 76 | } 77 | 78 | } 79 | 80 | /** 81 | * Properties of the RemoteParameters 82 | */ 83 | export interface RemoteParametersProps { 84 | // /** 85 | // * The remote CDK stack to get the parameters from. 86 | // */ 87 | // readonly stack: cdk.Stack; 88 | /** 89 | * The region code of the remote stack. 90 | */ 91 | readonly region: string; 92 | /** 93 | * The assumed role used to get remote parameters. 94 | */ 95 | readonly role?: iam.IRole; 96 | /** 97 | * The parameter path. 98 | */ 99 | readonly path: string; 100 | /** 101 | * Indicate whether always update the custom resource to get the new stack output 102 | * @default true 103 | */ 104 | readonly alwaysUpdate?: boolean; 105 | /** 106 | * timeout for custom resource handler 107 | * @default - no timeout specified. 108 | */ 109 | readonly timeout?: Duration; 110 | } 111 | 112 | /** 113 | * Represents the RemoteParameters of the remote CDK stack 114 | */ 115 | export class RemoteParameters extends Construct { 116 | /** 117 | * The parameters in the SSM parameter store for the remote stack. 118 | */ 119 | readonly parameters: CustomResource; 120 | 121 | constructor(scope: Construct, id: string, props: RemoteParametersProps) { 122 | super(scope, id); 123 | 124 | const onEvent = new lambda.Function(this, 'MyHandler', { 125 | runtime: lambda.Runtime.PYTHON_3_9, 126 | code: lambda.Code.fromAsset(path.join(__dirname, '../custom-resource-handler')), 127 | handler: 'remote-parameters.on_event', 128 | timeout: props.timeout, 129 | }); 130 | 131 | const myProvider = new cr.Provider(this, 'MyProvider', { 132 | onEventHandler: onEvent, 133 | logRetention: logs.RetentionDays.ONE_DAY, 134 | }); 135 | 136 | onEvent.addToRolePolicy(new iam.PolicyStatement({ 137 | actions: ['ssm:GetParametersByPath'], 138 | resources: ['*'], 139 | })); 140 | 141 | this.parameters = new CustomResource(this, 'SsmParameters', { 142 | serviceToken: myProvider.serviceToken, 143 | properties: { 144 | stackName: Stack.of(this).stackName, 145 | regionName: props.region, 146 | parameterPath: props.path, 147 | randomString: props.alwaysUpdate == false ? undefined : randomString(), 148 | role: props.role?.roleArn, 149 | }, 150 | }); 151 | 152 | if (props.role) { 153 | myProvider.onEventHandler.addToRolePolicy(new iam.PolicyStatement({ 154 | actions: ['sts:AssumeRole'], 155 | resources: [props.role.roleArn], 156 | })); 157 | } 158 | } 159 | 160 | /** 161 | * Get the parameter. 162 | * @param key output key 163 | */ 164 | public get(key: string) { 165 | return this.parameters.getAttString(key); 166 | } 167 | 168 | } 169 | 170 | 171 | function randomString() { 172 | // Crazy 173 | return Math.random().toString(36).replace(/[^a-z0-9]+/g, ''); 174 | } 175 | -------------------------------------------------------------------------------- /src/integ.default.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Stack, App, PhysicalName, CfnOutput, 3 | aws_iam as iam, 4 | aws_ssm as ssm, 5 | } from 'aws-cdk-lib'; 6 | 7 | import { RemoteParameters, RemoteOutputs } from './'; 8 | 9 | export class IntegTesting { 10 | readonly stack: Stack[]; 11 | 12 | constructor() { 13 | 14 | const app = new App(); 15 | 16 | const envJP = { 17 | region: 'ap-northeast-1', 18 | account: process.env.CDK_DEFAULT_ACCOUNT, 19 | }; 20 | 21 | const envUS = { 22 | region: 'us-west-2', 23 | account: process.env.CDK_DEFAULT_ACCOUNT, 24 | }; 25 | 26 | // first stack in JP 27 | const stackJP = new Stack(app, 'demo-stack-jp', { env: envJP }); 28 | 29 | new CfnOutput(stackJP, 'TopicName', { value: 'foo' }); 30 | 31 | // second stack in US 32 | const stackUS = new Stack(app, 'demo-stack-us', { env: envUS }); 33 | 34 | // ensure the dependency 35 | stackUS.addDependency(stackJP); 36 | 37 | // get the stackJP stack outputs from stackUS 38 | const outputs = new RemoteOutputs(stackUS, 'Outputs', { 39 | stack: stackJP, 40 | alwaysUpdate: false, 41 | }); 42 | 43 | const remoteOutputValue = outputs.get('TopicName'); 44 | 45 | // the value should be exactly the same with the output value of `TopicName` 46 | new CfnOutput(stackUS, 'RemoteTopicName', { value: remoteOutputValue }); 47 | 48 | this.stack = [stackJP, stackUS]; 49 | } 50 | } 51 | 52 | export class IntegSsmParameters { 53 | readonly stack: Stack[]; 54 | 55 | constructor() { 56 | 57 | const app = new App(); 58 | 59 | const envJP = { 60 | region: 'ap-northeast-1', 61 | account: '111111111111', 62 | }; 63 | 64 | const envUS = { 65 | region: 'us-west-2', 66 | account: '222222222222', 67 | }; 68 | 69 | // first stack in JP 70 | const producerStackName = 'demo-stack-jp'; 71 | const stackJP = new Stack(app, producerStackName, { env: envJP }); 72 | const parameterPath = `/${envJP.account}/${envJP.region}/${producerStackName}`; 73 | 74 | new ssm.StringParameter(stackJP, 'foo1', { 75 | 76 | parameterName: `${parameterPath}/foo1`, 77 | stringValue: 'bar1', 78 | }); 79 | new ssm.StringParameter(stackJP, 'foo2', { 80 | parameterName: `${parameterPath}/foo2`, 81 | stringValue: 'bar2', 82 | }); 83 | new ssm.StringParameter(stackJP, 'foo3', { 84 | parameterName: `${parameterPath}/foo3`, 85 | stringValue: 'bar3', 86 | }); 87 | 88 | // allow US account to assume this readonly role to get parameters 89 | const cdkReadOnlyRole = new iam.Role(stackJP, 'readOnlyRole', { 90 | assumedBy: new iam.AccountPrincipal(envUS.account), 91 | roleName: PhysicalName.GENERATE_IF_NEEDED, 92 | managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMReadOnlyAccess')], 93 | }); 94 | 95 | // second stack in US 96 | const stackUS = new Stack(app, 'demo-stack-us', { env: envUS }); 97 | 98 | // ensure the dependency 99 | stackUS.addDependency(stackJP); 100 | 101 | // get remote parameters by path from SSM parameter store 102 | const parameters = new RemoteParameters(stackUS, 'Parameters', { 103 | path: parameterPath, 104 | region: stackJP.region, 105 | // assume this role for cross-account parameters 106 | role: iam.Role.fromRoleArn(stackUS, 'readOnlyRole', cdkReadOnlyRole.roleArn), 107 | }); 108 | 109 | const foo1 = parameters.get(`${parameterPath}/foo1`); 110 | const foo2 = parameters.get(`${parameterPath}/foo2`); 111 | const foo3 = parameters.get(`${parameterPath}/foo3`); 112 | 113 | new CfnOutput(stackUS, 'foo1Output', { value: foo1 }); 114 | new CfnOutput(stackUS, 'foo2Output', { value: foo2 }); 115 | new CfnOutput(stackUS, 'foo3Output', { value: foo3 }); 116 | 117 | this.stack = [stackJP, stackUS]; 118 | } 119 | } 120 | 121 | new IntegTesting(); 122 | new IntegSsmParameters(); 123 | -------------------------------------------------------------------------------- /test/__snapshots__/integ.main.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`default validation 1`] = ` 4 | Object { 5 | "Outputs": Object { 6 | "TopicName": Object { 7 | "Value": "foo", 8 | }, 9 | }, 10 | "Parameters": Object { 11 | "BootstrapVersion": Object { 12 | "Default": "/cdk-bootstrap/hnb659fds/version", 13 | "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", 14 | "Type": "AWS::SSM::Parameter::Value", 15 | }, 16 | }, 17 | "Rules": Object { 18 | "CheckBootstrapVersion": Object { 19 | "Assertions": Array [ 20 | Object { 21 | "Assert": Object { 22 | "Fn::Not": Array [ 23 | Object { 24 | "Fn::Contains": Array [ 25 | Array [ 26 | "1", 27 | "2", 28 | "3", 29 | "4", 30 | "5", 31 | ], 32 | Object { 33 | "Ref": "BootstrapVersion", 34 | }, 35 | ], 36 | }, 37 | ], 38 | }, 39 | "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", 40 | }, 41 | ], 42 | }, 43 | }, 44 | } 45 | `; 46 | 47 | exports[`default validation 2`] = ` 48 | Object { 49 | "Outputs": Object { 50 | "RemoteTopicName": Object { 51 | "Value": Object { 52 | "Fn::GetAtt": Array [ 53 | "OutputsRemoteOutputs3D146D89", 54 | "TopicName", 55 | ], 56 | }, 57 | }, 58 | }, 59 | "Parameters": Object { 60 | "BootstrapVersion": Object { 61 | "Default": "/cdk-bootstrap/hnb659fds/version", 62 | "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", 63 | "Type": "AWS::SSM::Parameter::Value", 64 | }, 65 | }, 66 | "Resources": Object { 67 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A": Object { 68 | "DependsOn": Array [ 69 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB", 70 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB", 71 | ], 72 | "Properties": Object { 73 | "Code": Object { 74 | "S3Bucket": Object { 75 | "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-us-west-2", 76 | }, 77 | "S3Key": "5fa1330271b8967d9254ba2d4a07144f8acefe8b77e6d6bba38261373a50d5f8.zip", 78 | }, 79 | "Handler": "index.handler", 80 | "Role": Object { 81 | "Fn::GetAtt": Array [ 82 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB", 83 | "Arn", 84 | ], 85 | }, 86 | "Runtime": "nodejs16.x", 87 | }, 88 | "Type": "AWS::Lambda::Function", 89 | }, 90 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB": Object { 91 | "Properties": Object { 92 | "AssumeRolePolicyDocument": Object { 93 | "Statement": Array [ 94 | Object { 95 | "Action": "sts:AssumeRole", 96 | "Effect": "Allow", 97 | "Principal": Object { 98 | "Service": "lambda.amazonaws.com", 99 | }, 100 | }, 101 | ], 102 | "Version": "2012-10-17", 103 | }, 104 | "ManagedPolicyArns": Array [ 105 | Object { 106 | "Fn::Join": Array [ 107 | "", 108 | Array [ 109 | "arn:", 110 | Object { 111 | "Ref": "AWS::Partition", 112 | }, 113 | ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", 114 | ], 115 | ], 116 | }, 117 | ], 118 | }, 119 | "Type": "AWS::IAM::Role", 120 | }, 121 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB": Object { 122 | "Properties": Object { 123 | "PolicyDocument": Object { 124 | "Statement": Array [ 125 | Object { 126 | "Action": Array [ 127 | "logs:PutRetentionPolicy", 128 | "logs:DeleteRetentionPolicy", 129 | ], 130 | "Effect": "Allow", 131 | "Resource": "*", 132 | }, 133 | ], 134 | "Version": "2012-10-17", 135 | }, 136 | "PolicyName": "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB", 137 | "Roles": Array [ 138 | Object { 139 | "Ref": "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB", 140 | }, 141 | ], 142 | }, 143 | "Type": "AWS::IAM::Policy", 144 | }, 145 | "OutputsMyHandlerF583D0C8": Object { 146 | "DependsOn": Array [ 147 | "OutputsMyHandlerServiceRoleDefaultPolicy7D012100", 148 | "OutputsMyHandlerServiceRole597B9B61", 149 | ], 150 | "Properties": Object { 151 | "Code": Object { 152 | "S3Bucket": Object { 153 | "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-us-west-2", 154 | }, 155 | "S3Key": "3803df2f6849acf50bb6577ee095a669940670e799f70a2be34893a399777bc3.zip", 156 | }, 157 | "Handler": "remote-outputs.on_event", 158 | "Role": Object { 159 | "Fn::GetAtt": Array [ 160 | "OutputsMyHandlerServiceRole597B9B61", 161 | "Arn", 162 | ], 163 | }, 164 | "Runtime": "python3.9", 165 | }, 166 | "Type": "AWS::Lambda::Function", 167 | }, 168 | "OutputsMyHandlerServiceRole597B9B61": Object { 169 | "Properties": Object { 170 | "AssumeRolePolicyDocument": Object { 171 | "Statement": Array [ 172 | Object { 173 | "Action": "sts:AssumeRole", 174 | "Effect": "Allow", 175 | "Principal": Object { 176 | "Service": "lambda.amazonaws.com", 177 | }, 178 | }, 179 | ], 180 | "Version": "2012-10-17", 181 | }, 182 | "ManagedPolicyArns": Array [ 183 | Object { 184 | "Fn::Join": Array [ 185 | "", 186 | Array [ 187 | "arn:", 188 | Object { 189 | "Ref": "AWS::Partition", 190 | }, 191 | ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", 192 | ], 193 | ], 194 | }, 195 | ], 196 | }, 197 | "Type": "AWS::IAM::Role", 198 | }, 199 | "OutputsMyHandlerServiceRoleDefaultPolicy7D012100": Object { 200 | "Properties": Object { 201 | "PolicyDocument": Object { 202 | "Statement": Array [ 203 | Object { 204 | "Action": "cloudformation:DescribeStacks", 205 | "Effect": "Allow", 206 | "Resource": "*", 207 | }, 208 | ], 209 | "Version": "2012-10-17", 210 | }, 211 | "PolicyName": "OutputsMyHandlerServiceRoleDefaultPolicy7D012100", 212 | "Roles": Array [ 213 | Object { 214 | "Ref": "OutputsMyHandlerServiceRole597B9B61", 215 | }, 216 | ], 217 | }, 218 | "Type": "AWS::IAM::Policy", 219 | }, 220 | "OutputsMyProviderframeworkonEvent64931F85": Object { 221 | "DependsOn": Array [ 222 | "OutputsMyProviderframeworkonEventServiceRoleDefaultPolicy95F14376", 223 | "OutputsMyProviderframeworkonEventServiceRole1269FAA8", 224 | ], 225 | "Properties": Object { 226 | "Code": Object { 227 | "S3Bucket": Object { 228 | "Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-us-west-2", 229 | }, 230 | "S3Key": "8e3d635893ea17fa3158623489cd42c680fad925b38de1ef51cb10d84f6e245e.zip", 231 | }, 232 | "Description": "AWS CDK resource provider framework - onEvent (demo-stack-us/Outputs/MyProvider)", 233 | "Environment": Object { 234 | "Variables": Object { 235 | "USER_ON_EVENT_FUNCTION_ARN": Object { 236 | "Fn::GetAtt": Array [ 237 | "OutputsMyHandlerF583D0C8", 238 | "Arn", 239 | ], 240 | }, 241 | }, 242 | }, 243 | "Handler": "framework.onEvent", 244 | "Role": Object { 245 | "Fn::GetAtt": Array [ 246 | "OutputsMyProviderframeworkonEventServiceRole1269FAA8", 247 | "Arn", 248 | ], 249 | }, 250 | "Runtime": "nodejs16.x", 251 | "Timeout": 900, 252 | }, 253 | "Type": "AWS::Lambda::Function", 254 | }, 255 | "OutputsMyProviderframeworkonEventLogRetention434DEDC5": Object { 256 | "Properties": Object { 257 | "LogGroupName": Object { 258 | "Fn::Join": Array [ 259 | "", 260 | Array [ 261 | "/aws/lambda/", 262 | Object { 263 | "Ref": "OutputsMyProviderframeworkonEvent64931F85", 264 | }, 265 | ], 266 | ], 267 | }, 268 | "RetentionInDays": 1, 269 | "ServiceToken": Object { 270 | "Fn::GetAtt": Array [ 271 | "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A", 272 | "Arn", 273 | ], 274 | }, 275 | }, 276 | "Type": "Custom::LogRetention", 277 | }, 278 | "OutputsMyProviderframeworkonEventServiceRole1269FAA8": Object { 279 | "Properties": Object { 280 | "AssumeRolePolicyDocument": Object { 281 | "Statement": Array [ 282 | Object { 283 | "Action": "sts:AssumeRole", 284 | "Effect": "Allow", 285 | "Principal": Object { 286 | "Service": "lambda.amazonaws.com", 287 | }, 288 | }, 289 | ], 290 | "Version": "2012-10-17", 291 | }, 292 | "ManagedPolicyArns": Array [ 293 | Object { 294 | "Fn::Join": Array [ 295 | "", 296 | Array [ 297 | "arn:", 298 | Object { 299 | "Ref": "AWS::Partition", 300 | }, 301 | ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", 302 | ], 303 | ], 304 | }, 305 | ], 306 | }, 307 | "Type": "AWS::IAM::Role", 308 | }, 309 | "OutputsMyProviderframeworkonEventServiceRoleDefaultPolicy95F14376": Object { 310 | "Properties": Object { 311 | "PolicyDocument": Object { 312 | "Statement": Array [ 313 | Object { 314 | "Action": "lambda:InvokeFunction", 315 | "Effect": "Allow", 316 | "Resource": Array [ 317 | Object { 318 | "Fn::GetAtt": Array [ 319 | "OutputsMyHandlerF583D0C8", 320 | "Arn", 321 | ], 322 | }, 323 | Object { 324 | "Fn::Join": Array [ 325 | "", 326 | Array [ 327 | Object { 328 | "Fn::GetAtt": Array [ 329 | "OutputsMyHandlerF583D0C8", 330 | "Arn", 331 | ], 332 | }, 333 | ":*", 334 | ], 335 | ], 336 | }, 337 | ], 338 | }, 339 | ], 340 | "Version": "2012-10-17", 341 | }, 342 | "PolicyName": "OutputsMyProviderframeworkonEventServiceRoleDefaultPolicy95F14376", 343 | "Roles": Array [ 344 | Object { 345 | "Ref": "OutputsMyProviderframeworkonEventServiceRole1269FAA8", 346 | }, 347 | ], 348 | }, 349 | "Type": "AWS::IAM::Policy", 350 | }, 351 | "OutputsRemoteOutputs3D146D89": Object { 352 | "DeletionPolicy": "Delete", 353 | "Properties": Object { 354 | "ServiceToken": Object { 355 | "Fn::GetAtt": Array [ 356 | "OutputsMyProviderframeworkonEvent64931F85", 357 | "Arn", 358 | ], 359 | }, 360 | "regionName": "ap-northeast-1", 361 | "stackName": "demo-stack-jp", 362 | }, 363 | "Type": "AWS::CloudFormation::CustomResource", 364 | "UpdateReplacePolicy": "Delete", 365 | }, 366 | }, 367 | "Rules": Object { 368 | "CheckBootstrapVersion": Object { 369 | "Assertions": Array [ 370 | Object { 371 | "Assert": Object { 372 | "Fn::Not": Array [ 373 | Object { 374 | "Fn::Contains": Array [ 375 | Array [ 376 | "1", 377 | "2", 378 | "3", 379 | "4", 380 | "5", 381 | ], 382 | Object { 383 | "Ref": "BootstrapVersion", 384 | }, 385 | ], 386 | }, 387 | ], 388 | }, 389 | "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", 390 | }, 391 | ], 392 | }, 393 | }, 394 | } 395 | `; 396 | -------------------------------------------------------------------------------- /test/integ.main.test.ts: -------------------------------------------------------------------------------- 1 | import { Template } from 'aws-cdk-lib/assertions'; 2 | import { IntegTesting } from '../src/integ.default'; 3 | 4 | test('default validation', () => { 5 | const integ = new IntegTesting(); 6 | integ.stack.forEach(stack => { 7 | const t = Template.fromStack(stack); 8 | // should match snapshot 9 | expect(t).toMatchSnapshot(); 10 | }); 11 | }); -------------------------------------------------------------------------------- /test/main.test.ts: -------------------------------------------------------------------------------- 1 | import * as cdk from 'aws-cdk-lib'; 2 | import { Template } from 'aws-cdk-lib/assertions'; 3 | import { RemoteOutputs, RemoteParameters } from '../src'; 4 | 5 | test('create the ServerlessAPI', () => { 6 | const app = new cdk.App(); 7 | 8 | const envJP = { 9 | region: 'ap-northeast-1', 10 | account: process.env.CDK_DEFAULT_ACCOUNT, 11 | }; 12 | 13 | const envUS = { 14 | region: 'us-west-2', 15 | account: process.env.CDK_DEFAULT_ACCOUNT, 16 | }; 17 | 18 | // first stack in JP 19 | const stackJP = new cdk.Stack(app, 'demo-stack-jp', { env: envJP }); 20 | 21 | new cdk.CfnOutput(stackJP, 'TopicName', { value: 'foo' }); 22 | 23 | // second stack in US 24 | const stackUS = new cdk.Stack(app, 'demo-stack-us', { env: envUS }); 25 | 26 | // get the stackJP stack outputs from stackUS 27 | const outputs = new RemoteOutputs(stackUS, 'Outputs', { stack: stackJP }); 28 | 29 | const remoteOutputValue = outputs.get('TopicName'); 30 | 31 | // the value should be exactly the same with the output value of `TopicName` 32 | new cdk.CfnOutput(stackUS, 'RemoteTopicName', { value: remoteOutputValue }); 33 | 34 | const t = cdk.assertions.Template.fromStack(stackUS); 35 | t.hasResourceProperties('AWS::CloudFormation::CustomResource', { 36 | ServiceToken: { 37 | 'Fn::GetAtt': [ 38 | 'OutputsMyProviderframeworkonEvent64931F85', 39 | 'Arn', 40 | ], 41 | }, 42 | stackName: 'demo-stack-jp', 43 | regionName: 'ap-northeast-1', 44 | }); 45 | }); 46 | 47 | 48 | // create tests for `RemoteOutputs` 49 | describe('RemoteOutputs', () => { 50 | test('RemoteOutputs creates the required resources', () => { 51 | // GIVEN 52 | const app = new cdk.App(); 53 | const stack = new cdk.Stack(app, 'LocalStack'); 54 | const remoteStack = new cdk.Stack(app, 'RemoteStack', { 55 | env: { 56 | region: 'us-east-1', 57 | account: '123456789012', 58 | }, 59 | }); 60 | 61 | // WHEN 62 | new RemoteOutputs(stack, 'RemoteOutputs', { 63 | stack: remoteStack, 64 | }); 65 | 66 | // THEN 67 | const t = Template.fromStack(stack); 68 | // should have a lambda function 69 | t.hasResourceProperties('AWS::Lambda::Function', { 70 | Handler: 'remote-outputs.on_event', 71 | Runtime: 'python3.9', 72 | }); 73 | 74 | // should have iam role with correct policies 75 | t.hasResourceProperties('AWS::IAM::Role', { 76 | AssumeRolePolicyDocument: { 77 | Statement: [ 78 | { 79 | Action: 'sts:AssumeRole', 80 | Effect: 'Allow', 81 | Principal: { 82 | Service: 'lambda.amazonaws.com', 83 | }, 84 | }, 85 | ], 86 | Version: '2012-10-17', 87 | }, 88 | ManagedPolicyArns: [ 89 | { 90 | 'Fn::Join': [ 91 | '', 92 | [ 93 | 'arn:', 94 | { Ref: 'AWS::Partition' }, 95 | ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole', 96 | ], 97 | ], 98 | }, 99 | ], 100 | }); 101 | }); 102 | test('RemoteOutputs with custom timeout', () => { 103 | // GIVEN 104 | const app = new cdk.App(); 105 | const stack = new cdk.Stack(app, 'LocalStack'); 106 | const remoteStack = new cdk.Stack(app, 'RemoteStack', { 107 | env: { 108 | region: 'us-east-1', 109 | account: '123456789012', 110 | }, 111 | }); 112 | 113 | // WHEN 114 | new RemoteOutputs(stack, 'RemoteOutputs', { 115 | stack: remoteStack, 116 | timeout: cdk.Duration.minutes(3), 117 | }); 118 | 119 | // THEN 120 | const t = Template.fromStack(stack); 121 | // should have a lambda function with correct timeout 122 | t.hasResourceProperties('AWS::Lambda::Function', { 123 | Handler: 'remote-outputs.on_event', 124 | Runtime: 'python3.9', 125 | Timeout: 180, 126 | }); 127 | }); 128 | 129 | }); 130 | 131 | describe('RemoteParameters', () => { 132 | test('creates the required resources', () => { 133 | // GIVEN 134 | const app = new cdk.App(); 135 | const stack = new cdk.Stack(app, 'LocalStack'); 136 | 137 | // WHEN 138 | new RemoteParameters(stack, 'RemoteParameters', { 139 | path: '/my/path', 140 | region: 'us-west-2', 141 | }); 142 | 143 | // THEN 144 | const t = Template.fromStack(stack); 145 | 146 | // should have a lambda function 147 | t.hasResourceProperties('AWS::Lambda::Function', { 148 | Handler: 'remote-parameters.on_event', 149 | Runtime: 'python3.9', 150 | }); 151 | 152 | // should have iam role with correct policies 153 | t.hasResourceProperties('AWS::IAM::Role', { 154 | AssumeRolePolicyDocument: { 155 | Statement: [ 156 | { 157 | Action: 'sts:AssumeRole', 158 | Effect: 'Allow', 159 | Principal: { 160 | Service: 'lambda.amazonaws.com', 161 | }, 162 | }, 163 | ], 164 | Version: '2012-10-17', 165 | }, 166 | ManagedPolicyArns: [ 167 | { 168 | 'Fn::Join': [ 169 | '', 170 | [ 171 | 'arn:', 172 | { Ref: 'AWS::Partition' }, 173 | ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole', 174 | ], 175 | ], 176 | }, 177 | ], 178 | }); 179 | }); 180 | test('RemoteParameters with custom timeout', () => { 181 | // GIVEN 182 | const app = new cdk.App(); 183 | const stack = new cdk.Stack(app, 'LocalStack'); 184 | 185 | // WHEN 186 | new RemoteParameters(stack, 'RemoteParameters', { 187 | path: '/my/path', 188 | region: 'us-west-2', 189 | timeout: cdk.Duration.minutes(3), 190 | }); 191 | 192 | // THEN 193 | const t = Template.fromStack(stack); 194 | // should have a lambda function with correct timeout 195 | t.hasResourceProperties('AWS::Lambda::Function', { 196 | Handler: 'remote-parameters.on_event', 197 | Runtime: 'python3.9', 198 | Timeout: 180, 199 | }); 200 | }); 201 | }); 202 | -------------------------------------------------------------------------------- /tsconfig.dev.json: -------------------------------------------------------------------------------- 1 | // ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". 2 | { 3 | "compilerOptions": { 4 | "alwaysStrict": true, 5 | "declaration": true, 6 | "esModuleInterop": true, 7 | "experimentalDecorators": true, 8 | "inlineSourceMap": true, 9 | "inlineSources": true, 10 | "lib": [ 11 | "es2019" 12 | ], 13 | "module": "CommonJS", 14 | "noEmitOnError": false, 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitAny": true, 17 | "noImplicitReturns": true, 18 | "noImplicitThis": true, 19 | "noUnusedLocals": true, 20 | "noUnusedParameters": true, 21 | "resolveJsonModule": true, 22 | "strict": true, 23 | "strictNullChecks": true, 24 | "strictPropertyInitialization": true, 25 | "stripInternal": true, 26 | "target": "ES2019" 27 | }, 28 | "include": [ 29 | "src/**/*.ts", 30 | "test/**/*.ts", 31 | ".projenrc.js" 32 | ], 33 | "exclude": [ 34 | "node_modules" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /version.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.136" 3 | } 4 | --------------------------------------------------------------------------------