├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── bin └── first-cdk-project.ts ├── cdk.context.json ├── cdk.json ├── jest.config.js ├── lib └── first-cdk-project-stack.ts ├── package-lock.json ├── package.json ├── test └── first-cdk-project.test.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | !jest.config.js 3 | *.d.ts 4 | node_modules 5 | 6 | # CDK asset staging directory 7 | .cdk.staging 8 | cdk.out 9 | 10 | # Parcel build directories 11 | .cache 12 | .build 13 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | !*.d.ts 3 | 4 | # CDK asset staging directory 5 | .cdk.staging 6 | cdk.out 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 bbarman4u 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to your CDK TypeScript project! 2 | 3 | You should explore the contents of this project. It demonstrates an AWS CDK app with an instance of a stack (`FirstCdkProjectStack`) 4 | which contains an Amazon SQS queue that is subscribed to an Amazon SNS topic. 5 | 6 | The `cdk.json` file tells the CDK Toolkit how to execute your app. 7 | 8 | ## Useful commands 9 | 10 | * `npm run build` compile typescript to js 11 | * `npm run watch` watch for changes and compile 12 | * `npm run test` perform the jest unit tests 13 | * `cdk deploy` deploy this stack to your default AWS account/region 14 | * `cdk diff` compare deployed stack with current state 15 | * `cdk synth` emits the synthesized CloudFormation template 16 | 17 | ## Building and Deploying as Part of a Pipeline 18 | The accompanying Azure DevOps Pipeline YAML file can be used to run the build and deploy the cloud formation stacks to AWS. 19 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Node.js 2 | # Build a general Node.js project with npm. 3 | # Add steps that analyze code, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/javascript 5 | 6 | trigger: 7 | - master 8 | 9 | pool: 10 | vmImage: 'ubuntu-latest' 11 | 12 | steps: 13 | - task: NodeTool@0 14 | inputs: 15 | versionSpec: '10.x' 16 | displayName: 'Install Node.js' 17 | 18 | - script: | 19 | sudo npm install -g aws-cdk 20 | npm install 21 | npm run build 22 | cdk synth 23 | displayName: 'npm install and build' 24 | - task: AWSShellScript@1 25 | inputs: 26 | awsCredentials: 'AWS-SANDBOX' 27 | regionName: 'us-east-1' 28 | scriptType: 'inline' 29 | inlineScript: 'cdk deploy --ci --require-approval never' 30 | disableAutoCwd: true 31 | workingDirectory: '$(System.DefaultWorkingDirectory)' 32 | failOnStandardError: false 33 | displayName: 'cdk deploy' 34 | 35 | -------------------------------------------------------------------------------- /bin/first-cdk-project.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import * as cdk from '@aws-cdk/core'; 3 | import { FirstCdkProjectStack } from '../lib/first-cdk-project-stack'; 4 | 5 | const app = new cdk.App(); 6 | new FirstCdkProjectStack(app, 'FirstCdkProjectStack'); 7 | -------------------------------------------------------------------------------- /cdk.context.json: -------------------------------------------------------------------------------- 1 | { 2 | "@aws-cdk/core:enableStackNameDuplicates": "true", 3 | "aws-cdk:enableDiffNoFail": "true" 4 | } 5 | -------------------------------------------------------------------------------- /cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "npx ts-node bin/first-cdk-project.ts" 3 | } 4 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/test'], 3 | testMatch: ['**/*.test.ts'], 4 | transform: { 5 | '^.+\\.tsx?$': 'ts-jest' 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /lib/first-cdk-project-stack.ts: -------------------------------------------------------------------------------- 1 | import * as sns from '@aws-cdk/aws-sns'; 2 | import * as subs from '@aws-cdk/aws-sns-subscriptions'; 3 | import * as sqs from '@aws-cdk/aws-sqs'; 4 | import * as cdk from '@aws-cdk/core'; 5 | 6 | export class FirstCdkProjectStack extends cdk.Stack { 7 | constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { 8 | super(scope, id, props); 9 | 10 | const queue = new sqs.Queue(this, 'FirstCdkProjectQueue', { 11 | visibilityTimeout: cdk.Duration.seconds(300) 12 | }); 13 | 14 | const topic = new sns.Topic(this, 'FirstCdkProjectTopic'); 15 | 16 | topic.addSubscription(new subs.SqsSubscription(queue)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "first-cdk-project", 3 | "version": "0.1.0", 4 | "bin": { 5 | "first-cdk-project": "bin/first-cdk-project.js" 6 | }, 7 | "scripts": { 8 | "build": "tsc", 9 | "watch": "tsc -w", 10 | "test": "jest", 11 | "cdk": "cdk" 12 | }, 13 | "devDependencies": { 14 | "aws-cdk": "1.31.0", 15 | "@aws-cdk/assert": "1.31.0", 16 | "@types/jest": "^24.0.22", 17 | "@types/node": "10.17.5", 18 | "jest": "^24.9.0", 19 | "ts-jest": "^24.1.0", 20 | "ts-node": "^8.1.0", 21 | "typescript": "~3.7.2" 22 | }, 23 | "dependencies": { 24 | "@aws-cdk/aws-sns": "1.31.0", 25 | "@aws-cdk/aws-sns-subscriptions": "1.31.0", 26 | "@aws-cdk/aws-sqs": "1.31.0", 27 | "@aws-cdk/core": "1.31.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/first-cdk-project.test.ts: -------------------------------------------------------------------------------- 1 | import { expect as expectCDK, haveResource } from '@aws-cdk/assert'; 2 | import * as cdk from '@aws-cdk/core'; 3 | import FirstCdkProject = require('../lib/first-cdk-project-stack'); 4 | 5 | test('SQS Queue Created', () => { 6 | const app = new cdk.App(); 7 | // WHEN 8 | const stack = new FirstCdkProject.FirstCdkProjectStack(app, 'MyTestStack'); 9 | // THEN 10 | expectCDK(stack).to(haveResource("AWS::SQS::Queue",{ 11 | VisibilityTimeout: 300 12 | })); 13 | }); 14 | 15 | test('SNS Topic Created', () => { 16 | const app = new cdk.App(); 17 | // WHEN 18 | const stack = new FirstCdkProject.FirstCdkProjectStack(app, 'MyTestStack'); 19 | // THEN 20 | expectCDK(stack).to(haveResource("AWS::SNS::Topic")); 21 | }); 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target":"ES2018", 4 | "module": "commonjs", 5 | "lib": ["es2018"], 6 | "declaration": true, 7 | "strict": true, 8 | "noImplicitAny": true, 9 | "strictNullChecks": true, 10 | "noImplicitThis": true, 11 | "alwaysStrict": true, 12 | "noUnusedLocals": false, 13 | "noUnusedParameters": false, 14 | "noImplicitReturns": true, 15 | "noFallthroughCasesInSwitch": false, 16 | "inlineSourceMap": true, 17 | "inlineSources": true, 18 | "experimentalDecorators": true, 19 | "strictPropertyInitialization":false, 20 | "typeRoots": ["./node_modules/@types"] 21 | }, 22 | "exclude": ["cdk.out"] 23 | } 24 | --------------------------------------------------------------------------------