This repository contains examples for testing your infrastructure code written with the AWS CDK. Unit tests are written with the Jest testing framework. Integration tests are written with the InSpec testing and auditing framework.
- Install the AWS CDK
npm install -g aws-cdk
You can find more CDK setup details here. The examples in this project are written with Typescript. - Install InSpec using these instructions.
- Install dependencies
npm install
- Run unit tests
npm run build && npm run test
- Setup your AWS credentials for InSpec
Following the instructions here, you can use environment variables or a profile in~/.aws/credentials
. - Synthesize
cdk synth
- Deploy your changes
cdk deploy --all --parameters FullStackAppStack:keyPairName=<your key pair name> --parameters S3BucketStack:bucketName=<your bucket name> --outputs-file inspec/files/outputs.json
- Run InSpec tests
inspec exec inspec -t aws://
If you get an error about the lockfile, deleteinspec/inspec.lock
and rerun the command.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation templatecdk destroy
destroys the stack and all associated resourcesinspec exec inspec -t aws://
runs the inspec integration tests for the inspec test profile