├── .eslintignore ├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── build.yml │ ├── pre-publish.yml │ └── publish.yml ├── .gitignore ├── .npmignore ├── .prettierrc ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── codecov.yml ├── lib └── index.ts ├── package-lock.json ├── package.json └── tests ├── delete.json ├── put.json └── seeder.ts /.eslintignore: -------------------------------------------------------------------------------- 1 | # don't ever lint node_modules 2 | node_modules 3 | # don't lint build output 4 | lib 5 | # don't lint nyc coverage output 6 | coverage 7 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | plugins: [ 5 | '@typescript-eslint', 6 | ], 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:@typescript-eslint/eslint-recommended', 10 | 'plugin:@typescript-eslint/recommended', 11 | ], 12 | }; 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: needs triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Evidence** 24 | If applicable, add screenshots, logs, etc, to help explain your problem. 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: suggestion 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ---- 4 | 5 | *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* 6 | 7 | 11 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - "*" 7 | tags-ignore: 8 | - "v*" 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [10.x, 12.x] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v1 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | - run: npm install 27 | - run: npm run build --if-present 28 | - run: npm test 29 | - name: Codecov 30 | uses: codecov/codecov-action@v1.0.5 31 | with: 32 | token: ${{ secrets.CODECOV_TOKEN }} 33 | node-version: 12.x 34 | env: 35 | CI: true 36 | -------------------------------------------------------------------------------- /.github/workflows/pre-publish.yml: -------------------------------------------------------------------------------- 1 | name: jsii pre-publish checks 2 | 3 | on: 4 | push: 5 | branches: 6 | - "*" 7 | tags-ignore: 8 | - "v*" 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [12.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | with: 24 | fetch-depth: 1 25 | 26 | - name: Use Node.js ${{ matrix.node-version }} 27 | uses: actions/setup-node@v1 28 | with: 29 | node-version: ${{ matrix.node-version }} 30 | 31 | - run: make 32 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: jsii publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | matrix: 15 | node-version: [12.x] 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 1 21 | 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v1 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | 27 | - run: make 28 | 29 | - run: make publish-npm 30 | env: 31 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 32 | 33 | - run: make publish-pypi 34 | env: 35 | PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} 36 | 37 | - run: make publish-nuget 38 | env: 39 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} 40 | 41 | - run: make publish-maven 42 | env: 43 | MAVEN_STAGING_PROFILE_ID: ${{ secrets.MAVEN_STAGING_PROFILE_ID }} 44 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 45 | MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} 46 | MAVEN_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} 47 | MAVEN_GPG_PRIVATE_KEY_PASSPHRASE: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_PASSPHRASE }} 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # npm 2 | node_modules/ 3 | .npm 4 | *.tgz 5 | 6 | # code coverage 7 | coverage/ 8 | 9 | # jsii 10 | tsconfig.json 11 | .jsii 12 | dist/ 13 | *.js 14 | *.d.ts 15 | .cdk.staging -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | tsconfig.json 3 | tslint.json 4 | .prettierrc 5 | 6 | 7 | # Exclude jsii outdir 8 | dist 9 | 10 | # Include .jsii 11 | !.jsii 12 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "trailingComma": "all", 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at projects@elegantdevelopment.co.uk. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute 2 | 3 | #### **Did you find a bug?** 4 | 5 | * **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/relegantdevelopment/aws-cdk-dynamodb-seeder/issues) 6 | 7 | * If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder/issues/new?template=bug_report.md). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring 8 | 9 | #### **Did you write a patch that fixes a bug?** 10 | 11 | * [Open a new GitHub pull request](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder/compare) with the patch 12 | 13 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable 14 | 15 | #### **Do you intend to add a new feature or change an existing one?** 16 | 17 | * [Open a new feature request](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder/issues/new?template=feature_request.md) and comprehensively describe what you'd like to see achieved 18 | 19 | Thanks! 20 | 21 | Elegant Development 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash -o pipefail 2 | 3 | DOCKER_IMAGE := jsii/superchain 4 | DOCKER_TAG := latest 5 | DOCKER_WORKDIR := /workdir 6 | 7 | build: 8 | docker run \ 9 | --workdir ${DOCKER_WORKDIR} \ 10 | --volume ${PWD}:${DOCKER_WORKDIR} \ 11 | ${DOCKER_IMAGE}:${DOCKER_TAG} \ 12 | /bin/bash -c "rm -rf dist && npm i && npm run package" 13 | 14 | publish-npm: 15 | docker run \ 16 | --workdir ${DOCKER_WORKDIR} \ 17 | --volume ${PWD}:${DOCKER_WORKDIR} \ 18 | --env NPM_TOKEN \ 19 | ${DOCKER_IMAGE}:${DOCKER_TAG} \ 20 | /bin/bash -c "npx jsii-release-npm dist/js" 21 | 22 | publish-nuget: 23 | docker run \ 24 | --workdir ${DOCKER_WORKDIR} \ 25 | --volume ${PWD}:${DOCKER_WORKDIR} \ 26 | --env NUGET_API_KEY \ 27 | ${DOCKER_IMAGE}:${DOCKER_TAG} \ 28 | /bin/bash -c "npx jsii-release-nuget dist/dotnet" 29 | 30 | publish-pypi: 31 | docker run \ 32 | --workdir ${DOCKER_WORKDIR} \ 33 | --volume ${PWD}:${DOCKER_WORKDIR} \ 34 | --env TWINE_USERNAME=__token__ \ 35 | --env TWINE_PASSWORD=$(PYPI_TOKEN) \ 36 | ${DOCKER_IMAGE}:${DOCKER_TAG} \ 37 | /bin/bash -c "npx jsii-release-pypi dist/python" 38 | 39 | publish-maven: 40 | docker run \ 41 | --workdir ${DOCKER_WORKDIR} \ 42 | --volume ${PWD}:${DOCKER_WORKDIR} \ 43 | --env MAVEN_STAGING_PROFILE_ID \ 44 | --env MAVEN_USERNAME \ 45 | --env MAVEN_PASSWORD \ 46 | --env MAVEN_GPG_PRIVATE_KEY \ 47 | --env MAVEN_GPG_PRIVATE_KEY_PASSPHRASE \ 48 | --env MAVEN_DRYRUN \ 49 | ${DOCKER_IMAGE}:${DOCKER_TAG} \ 50 | /bin/bash -c "npx jsii-release-maven dist/java" 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-cdk-dynamodb-seeder [![Mentioned in Awesome CDK](https://awesome.re/mentioned-badge.svg)](https://github.com/eladb/awesome-cdk) 2 | 3 | ![build](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder/workflows/build/badge.svg) 4 | [![codecov](https://codecov.io/gh/elegantdevelopment/aws-cdk-dynamodb-seeder/branch/master/graph/badge.svg)](https://codecov.io/gh/elegantdevelopment/aws-cdk-dynamodb-seeder) 5 | [![dependencies Status](https://david-dm.org/elegantdevelopment/aws-cdk-dynamodb-seeder/status.svg)](https://david-dm.org/elegantdevelopment/aws-cdk-dynamodb-seeder) 6 | [![npm](https://img.shields.io/npm/dt/aws-cdk-dynamodb-seeder)](https://www.npmjs.com/package/aws-cdk-dynamodb-seeder) 7 | 8 | [![npm version](https://badge.fury.io/js/aws-cdk-dynamodb-seeder.svg)](https://badge.fury.io/js/aws-cdk-dynamodb-seeder) 9 | [![NuGet version](https://badge.fury.io/nu/ElegantDevelopment.AWSCDKDynamoDBSeeder.svg)](https://badge.fury.io/nu/ElegantDevelopment.AWSCDKDynamoDBSeeder) 10 | [![PyPI version](https://badge.fury.io/py/aws-cdk-dynamodb-seeder.svg)](https://badge.fury.io/py/aws-cdk-dynamodb-seeder) 11 | [![Maven Central](https://img.shields.io/maven-central/v/io.github.elegantdevelopment/AWSCDKDynamoDBSeeder?color=brightgreen)](https://repo1.maven.org/maven2/io/github/elegantdevelopment/AWSCDKDynamoDBSeeder/) 12 | 13 | A simple CDK JSON seeder for DynamoDB 14 | 15 | ## Why this package 16 | 17 | Glad you asked! 18 | 19 | Using [AWS CDK] for automating infrastructure deployments is an amazing way of integrating the development and operations into one process and one codebase. 20 | 21 | However, building dev or test environments that come pre-populated with data can be tricky, especially when using [Amazon DynamoDB]. 22 | 23 | ## How do I use it 24 | 25 | Install using your favourite package manager: 26 | 27 | ```sh 28 | yarn add aws-cdk-dynamodb-seeder 29 | ``` 30 | 31 | ### Example TypeScript usage 32 | 33 | ```ts 34 | import { Seeder } from 'aws-cdk-dynamodb-seeder'; 35 | ... 36 | const myTable = new Table(stack, "MyTable", { 37 | tableName: "MyTable", 38 | partitionKey: { name: "Id", type: AttributeType.STRING }, 39 | }); 40 | ... 41 | new Seeder(stack, "MySeeder", { 42 | table: myTable, 43 | setup: require("./items-to-put.json"), 44 | teardown: require("./keys-to-delete.json"), 45 | refreshOnUpdate: true // runs setup and teardown on every update, default false 46 | }); 47 | ``` 48 | 49 | For a more in-depth example, see: [elegantdevelopment/aws-cdk-dynamodb-seeder-examples](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder-examples). 50 | 51 | ### Importing seed data 52 | 53 | Data passed into `setup` ("Items" to put) or `teardown` ("Keys" to delete) should be an `array` of objects (that are, in turn, representations of `string` to [AttributeValue] maps). 54 | 55 | * `setup` elements should use the format of `params.Item` from [AWS.DynamoDB.DocumentClient.put()] 56 | * `teardown` elements should use the format of `params.Key` from [AWS.DynamoDB.DocumentClient.delete()] 57 | 58 | ## Versioning 59 | 60 | We will *attempt* to align the major and minor version of this package with [AWS CDK], but always check our release descriptions for compatibility. 61 | 62 | We currently support [![GitHub package.json dependency version (prod)](https://img.shields.io/github/package-json/dependency-version/elegantdevelopment/aws-cdk-dynamodb-seeder-examples/@aws-cdk/core)](https://github.com/aws/aws-cdk) 63 | 64 | ## Internals 65 | 66 | Behind the scenes we use an [AwsCustomResource] as a representation of the related table's seed state. The custom resource's event handlers invoke a [Function] to perform setup and/or teardown actions. 67 | 68 | ### Deploying a stack 69 | 70 | On deployment, we write copies of your seed data locally and use a [BucketDeployment] to write it to an S3 [Bucket]. 71 | 72 | We then create the handler function and custom resource to field seed requests (the `onCreate` event will immediate fire as the stack deploys, reading the data from the bucket and seeding the table using [AWS.DynamoDB.DocumentClient]). 73 | 74 | ### Updating a stack 75 | 76 | On a stack update, the `onUpdate` handler is triggered when `refreshOnUpdate` is `true`. 77 | 78 | This will run [AWS.DynamoDB.DocumentClient.delete()] on every teardown "Key" followed by [AWS.DynamoDB.DocumentClient.put()] on every setup "Item". 79 | 80 | ### Destroying a stack 81 | 82 | When the stack is destroyed, the event handler's `onDelete` function will be invoked, providing `teardown` is set. 83 | 84 | This simply runs [AWS.DynamoDB.DocumentClient.delete()] on every teardown "Key" before destroying the `Seeder`'s resources. 85 | 86 | [aws cdk]: https://aws.amazon.com/cdk 87 | [amazon dynamodb]: https://aws.amazon.com/dynamodb 88 | 89 | [AttributeValue]: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html 90 | [AWS.DynamoDB.DocumentClient]: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html 91 | [AWS.DynamoDB.DocumentClient.put()]: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#put-property 92 | [AWS.DynamoDB.DocumentClient.delete()]: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#delete-property 93 | 94 | 95 | [AwsCustomResource]: https://docs.aws.amazon.com/cdk/api/latest/typescript/api/custom-resources/awscustomresource.html 96 | [Function]: https://docs.aws.amazon.com/cdk/api/latest/typescript/api/aws-lambda/function.html#aws_lambda_Function 97 | [Bucket]: https://docs.aws.amazon.com/cdk/api/latest/typescript/api/aws-s3/bucket.html#aws_s3_Bucket 98 | [BucketDeployment]: https://docs.aws.amazon.com/cdk/api/latest/typescript/api/aws-s3-deployment/bucketdeployment.html#aws_s3_deployment_BucketDeployment 99 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | precision: 2 3 | round: down 4 | range: "60...100" 5 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | import { Construct, RemovalPolicy, Duration } from '@aws-cdk/core'; 2 | import { Table } from '@aws-cdk/aws-dynamodb'; 3 | import { Function, Runtime, Code } from '@aws-cdk/aws-lambda'; 4 | import { Bucket } from '@aws-cdk/aws-s3'; 5 | import { BucketDeployment, Source } from '@aws-cdk/aws-s3-deployment'; 6 | import { AwsCustomResource, AwsSdkCall, AwsCustomResourcePolicy } from '@aws-cdk/custom-resources'; 7 | import * as tmp from 'tmp'; 8 | import * as fs from 'fs'; 9 | 10 | export interface Props { 11 | readonly table: Table; 12 | readonly setup: Item[]; 13 | readonly teardown?: ItemKey[]; 14 | readonly refreshOnUpdate?: boolean; 15 | } 16 | 17 | export interface ItemKey { 18 | [key: string]: string | number; 19 | } 20 | 21 | export interface Item { 22 | [key: string]: any; 23 | } 24 | 25 | export class Seeder extends Construct { 26 | protected props: Props; 27 | constructor(scope: Construct, id: string, props: Props) { 28 | super(scope, id); 29 | if (!props.setup || !Array.isArray(props.setup)) throw new Error('setup value must be an array of JSON objects'); 30 | this.props = props; 31 | 32 | const destinationBucket = new Bucket(this, 'acds-bucket', { 33 | removalPolicy: RemovalPolicy.DESTROY, 34 | }); 35 | tmp.setGracefulCleanup(); 36 | tmp.dir((err, dir) => { 37 | if (err) throw err; 38 | this.writeTempFile(dir, 'setup.json', props.setup); 39 | if (props.teardown) { 40 | this.writeTempFile(dir, 'teardown.json', props.teardown); 41 | } 42 | new BucketDeployment(this, id, { 43 | sources: [Source.asset(dir)], 44 | destinationBucket, 45 | retainOnDelete: false, 46 | }); 47 | }); 48 | 49 | const fn = new Function(this, 'handler', { 50 | runtime: Runtime.NODEJS_12_X, 51 | handler: 'index.handler', 52 | timeout: Duration.seconds(900), 53 | code: Code.fromInline(` 54 | console.log('function loaded'); 55 | 56 | const AWS = require('aws-sdk'); 57 | const s3 = new AWS.S3(); 58 | 59 | const writeTypeFromAction = (action) => { 60 | if (action === "Put") 61 | return "Item"; 62 | if (action === "Delete") 63 | return "Key"; 64 | } 65 | 66 | const run = async (filename, action) => { 67 | console.log('reading from s3'); 68 | const data = await s3.getObject({ 69 | Bucket: "${destinationBucket.bucketName}", 70 | Key: filename 71 | }).promise(); 72 | console.log('finished reading from s3'); 73 | 74 | console.log('transforming seed data'); 75 | const seed = JSON.parse(data.Body.toString()); 76 | console.log('finished transforming seed data'); 77 | 78 | const documentClient = new AWS.DynamoDB.DocumentClient({ 79 | convertEmptyValues: true 80 | }); 81 | console.log('sending data to dynamodb'); 82 | do { 83 | const requests = []; 84 | const batch = seed.splice(0, 25); 85 | for (let i = 0; i < batch.length; i++) { 86 | requests.push({ 87 | [action + "Request"]: { 88 | [writeTypeFromAction(action)]: batch[i] 89 | } 90 | }); 91 | } 92 | await documentClient.batchWrite({ 93 | RequestItems: { 94 | '${props.table.tableName}': [...requests] 95 | } 96 | }).promise(); 97 | } 98 | while (seed.length > 0); 99 | console.log('finished sending data to dynamodb'); 100 | } 101 | 102 | exports.handler = async (event) => { 103 | if (event.mode === "delete") 104 | await run("teardown.json", "Delete"); 105 | if (event.mode === "create" || event.mode === "update") 106 | await run("setup.json", "Put"); 107 | }`), 108 | }); 109 | destinationBucket.grantRead(fn); 110 | props.table.grantWriteData(fn); 111 | 112 | const onEvent = new AwsCustomResource(this, 'on-event', { 113 | onCreate: { 114 | ...this.callLambdaOptions(), 115 | parameters: { 116 | FunctionName: fn.functionArn, 117 | InvokeArgs: JSON.stringify({ 118 | mode: 'create', 119 | }), 120 | }, 121 | }, 122 | onDelete: props.teardown 123 | ? { 124 | ...this.callLambdaOptions(), 125 | parameters: { 126 | FunctionName: fn.functionArn, 127 | InvokeArgs: JSON.stringify({ 128 | mode: 'delete', 129 | }), 130 | }, 131 | } 132 | : undefined, 133 | onUpdate: props.refreshOnUpdate 134 | ? { 135 | ...this.callLambdaOptions(), 136 | parameters: { 137 | FunctionName: fn.functionArn, 138 | InvokeArgs: JSON.stringify({ 139 | mode: 'update', 140 | }), 141 | }, 142 | } 143 | : undefined, 144 | policy: AwsCustomResourcePolicy.fromSdkCalls({ resources: AwsCustomResourcePolicy.ANY_RESOURCE }), 145 | }); 146 | fn.grantInvoke(onEvent); 147 | } 148 | 149 | private callLambdaOptions(): AwsSdkCall { 150 | return { 151 | service: 'Lambda', 152 | action: 'invokeAsync', 153 | apiVersion: '2015-03-31', 154 | physicalResourceId: { 155 | id: `${this.props.table.tableArn}-seeder`, 156 | }, 157 | }; 158 | } 159 | 160 | private writeTempFile(dir: string, filename: string, data: Item[] | ItemKey[]): void { 161 | const buffer = Buffer.from(JSON.stringify(data)); 162 | const filepath = dir + '/' + filename; 163 | fs.writeFileSync(filepath, buffer); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aws-cdk-dynamodb-seeder", 3 | "version": "1.56.1", 4 | "description": "A simple CDK JSON seeder for DynamoDB", 5 | "scripts": { 6 | "build": "jsii", 7 | "build:watch": "jsii -w", 8 | "package": "jsii-pacmak", 9 | "cdk": "cdk", 10 | "check": "npm test && npm run lint", 11 | "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", 12 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx", 13 | "postversion": "git push && git push --tags", 14 | "prepare": "npm run build", 15 | "prepublishOnly": "npm run check", 16 | "preversion": "npm run lint", 17 | "test": "jest", 18 | "version": "npm run format && git add -A src" 19 | }, 20 | "main": "lib/index.js", 21 | "types": "lib/index.d.ts", 22 | "jsii": { 23 | "outdir": "dist", 24 | "versionFormat": "short", 25 | "excludeTypescript": [ 26 | "tests" 27 | ], 28 | "targets": { 29 | "python": { 30 | "distName": "aws-cdk-dynamodb-seeder", 31 | "module": "ElegantDevelopment.AWSCDKDynamoDBSeeder" 32 | }, 33 | "dotnet": { 34 | "namespace": "ElegantDevelopment.AWSCDKDynamoDBSeeder", 35 | "packageId": "ElegantDevelopment.AWSCDKDynamoDBSeeder" 36 | }, 37 | "java": { 38 | "package": "io.github.elegantdevelopment.AWSCDKDynamoDBSeeder", 39 | "maven": { 40 | "groupId": "io.github.elegantdevelopment", 41 | "artifactId": "AWSCDKDynamoDBSeeder" 42 | } 43 | } 44 | } 45 | }, 46 | "awscdkio": { 47 | "twitter": "elegant_dev" 48 | }, 49 | "stability": "experimental", 50 | "repository": { 51 | "type": "git", 52 | "url": "https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder.git" 53 | }, 54 | "keywords": [ 55 | "aws", 56 | "cdk", 57 | "dynamodb", 58 | "seed", 59 | "seeder" 60 | ], 61 | "author": { 62 | "name": "Justin Taylor", 63 | "email": "jtaylor@elegantdevelopment.co.uk", 64 | "url": "https://github.com/jsdtaylor" 65 | }, 66 | "license": "Apache-2.0", 67 | "bugs": { 68 | "url": "https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder/issues" 69 | }, 70 | "homepage": "https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder#readme", 71 | "dependencies": { 72 | "@aws-cdk/aws-dynamodb": "^1.56.0", 73 | "@aws-cdk/aws-lambda": "^1.56.0", 74 | "@aws-cdk/aws-s3": "^1.56.0", 75 | "@aws-cdk/aws-s3-deployment": "^1.56.0", 76 | "@aws-cdk/core": "^1.56.0", 77 | "@aws-cdk/custom-resources": "^1.56.0", 78 | "aws-sdk": "^2.725.0", 79 | "constructs": "^3.0.4", 80 | "tmp": "^0.1.0" 81 | }, 82 | "devDependencies": { 83 | "@aws-cdk/assert": "^1.56.0", 84 | "@types/jest": "^25.2.3", 85 | "@types/node": "^13.13.15", 86 | "@types/tmp": "^0.1.0", 87 | "@typescript-eslint/eslint-plugin": "^2.34.0", 88 | "@typescript-eslint/parser": "^2.34.0", 89 | "aws-cdk": "^1.56.0", 90 | "eslint": "^6.8.0", 91 | "jest": "^25.5.4", 92 | "jsii": "^1.9.0", 93 | "jsii-pacmak": "^1.9.0", 94 | "jsii-release": "^0.1.9", 95 | "minimist": ">=1.2.2", 96 | "prettier": "^1.19.1", 97 | "ts-jest": "^25.5.1", 98 | "typescript": "^3.9.7" 99 | }, 100 | "jest": { 101 | "transform": { 102 | "^.+\\.tsx?$": "ts-jest" 103 | }, 104 | "testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", 105 | "collectCoverage": true, 106 | "collectCoverageFrom": [ 107 | "lib/*.ts", 108 | "!node_modules/**" 109 | ], 110 | "moduleFileExtensions": [ 111 | "ts", 112 | "tsx", 113 | "js", 114 | "jsx", 115 | "json", 116 | "node" 117 | ], 118 | "globals": { 119 | "ts-jest": { 120 | "diagnostics": { 121 | "warnOnly": true 122 | } 123 | }, 124 | "testEnvironment": "node" 125 | } 126 | }, 127 | "peerDependencies": { 128 | "@aws-cdk/aws-dynamodb": "^1.56.0", 129 | "@aws-cdk/aws-lambda": "^1.56.0", 130 | "@aws-cdk/aws-s3": "^1.56.0", 131 | "@aws-cdk/aws-s3-deployment": "^1.56.0", 132 | "@aws-cdk/core": "^1.56.0", 133 | "@aws-cdk/custom-resources": "^1.56.0", 134 | "constructs": "^3.0.4" 135 | }, 136 | "bundledDependencies": [ 137 | "aws-sdk", 138 | "tmp" 139 | ] 140 | } 141 | -------------------------------------------------------------------------------- /tests/delete.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "greatest show" 4 | } 5 | ] 6 | -------------------------------------------------------------------------------- /tests/put.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "herewego...", 4 | "this": "is a test", 5 | "testing": { 6 | "testing": 123 7 | } 8 | }, 9 | { 10 | "id": "greatest show", 11 | "this": "is a the greatest show" 12 | } 13 | ] 14 | -------------------------------------------------------------------------------- /tests/seeder.ts: -------------------------------------------------------------------------------- 1 | import { Stack } from '@aws-cdk/core'; 2 | import { Table, AttributeType } from '@aws-cdk/aws-dynamodb'; 3 | import '@aws-cdk/assert/jest'; 4 | 5 | import { Seeder } from '../lib/index'; 6 | 7 | it('seeds a table from required json files', () => { 8 | const stack = new Stack(); 9 | new Seeder(stack, 'Seeder', { 10 | table: new Table(stack, 'TestTable', { 11 | tableName: 'TestTable', 12 | partitionKey: { name: 'Id', type: AttributeType.STRING }, 13 | }), 14 | setup: require('./put.json'), 15 | teardown: require('./delete.json'), 16 | refreshOnUpdate: true, 17 | }); 18 | 19 | expect(stack).toHaveResource('AWS::Lambda::Function'); 20 | expect(stack).toHaveResource('AWS::S3::Bucket'); 21 | }); 22 | 23 | it('seeds a table from inline arrays', () => { 24 | const stack = new Stack(); 25 | new Seeder(stack, 'Seeder', { 26 | table: new Table(stack, 'TestTable', { 27 | tableName: 'TestTable', 28 | partitionKey: { name: 'Id', type: AttributeType.STRING }, 29 | }), 30 | setup: [ 31 | { 32 | id: 'herewego...', 33 | this: 'is a test', 34 | testing: { 35 | testing: 123, 36 | }, 37 | }, 38 | { 39 | id: 'greatest show', 40 | this: 'is a the greatest show', 41 | }, 42 | ], 43 | teardown: [ 44 | { 45 | id: 'greatest show', 46 | }, 47 | ], 48 | refreshOnUpdate: true, 49 | }); 50 | 51 | expect(stack).toHaveResource('AWS::Lambda::Function'); 52 | expect(stack).toHaveResource('AWS::S3::Bucket'); 53 | }); 54 | --------------------------------------------------------------------------------