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.lockand rerun the command.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation templatecdk destroydestroys the stack and all associated resourcesinspec exec inspec -t aws://runs the inspec integration tests for the inspec test profile