There are logical IDs which are used by CloudFormation to identify resources uniquely within a stack
CDK is a higher level of abstraction over CloudFormation letting you write in your chosen language
CDK is composed of constructs which are higher levels of abstraction over base CloudFormation resources
Everything is in a CDK app, and then associated with a Stack
Snapshot testing to check that nothing has changed
import { Template } from 'aws-cdk-lib/assertions';
const template = Template.fromStack(stack);
const result = JSON.stringify(template).replace(
/"S3Key":"[^"]+"/g,
'"S3Key":"[REMOVED]"',
);
expect(JSON.parse(result)).toMatchSnapshot();
- Prefer to be overly verbose because infrastructure typically doesn't change
- `progress: events` is helpful for logging in CI/CD
- Stateless vs Stateful resources
- Changing logical IDs will cause resources to be created and destroyed
- Sometimes you will want to prefer not explicitly setting a name so that CDK can handle cutover of resource creation / deletion under the hood
- Construct trees
- If you're using NodeJsFunction, make sure your CI agent has git and bash
References:
- Don't change logical IDs: https://docs.aws.amazon.com/cdk/v2/guide/identifiers.html#identifiers_logical_ids
- Current set of feature flags: https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/FEATURE_FLAGS.md
const template = Template.fromStack(stack);
const result = JSON.stringify(template).replace( /"S3Key":"[^"]+"/g, '"S3Key":"[REMOVED]"', );
expect(JSON.parse(result)).toMatchSnapshot();