CDK Aspects for Flipdish serverless applications
npm install @flipdish/cdk-aspectsCDK Aspects for Flipdish Serverless Applications that provide consistent AWS resource configuration and tagging across our infrastructure.
``bash`
npm install @flipdish/cdk-aspects
The package provides CDK Aspects that can be used to enforce consistent configuration and tagging across your AWS resources. Import and use the aspects in your SST configuration:
`typescript
import { TableSettingsAspect, TagsAspect, addAspects } from '@flipdish/cdk-aspects';
// In your SST config
export default {
async stacks(app) {
// Add standard aspects
addAspects(app, [
new TagsAspect(serviceName, datadogTeamName),
new TableSettingsAspect(app.stage)
]);
// ... rest of your stack configuration
}
} as SSTConfig;
`
Applies consistent tagging across all resources in your stacks. This includes service name and team name tags that are useful for resource organization and cost allocation.
`typescript`
new TagsAspect(serviceName, teamName)
Enforces consistent DynamoDB table settings across your application. This aspect ensures:
- PAY_PER_REQUEST billing mode
- Point-in-time recovery enabled
- Appropriate partition key (pk) and sort key (sk) naming
- Proper removal policies based on stage (RETAIN for production, DELETE for development)
`typescript`
new TableSettingsAspect(stage)
This section is only relevant if you are working within the serverless-app-template repository, where this package is maintained.
1. Local Development:
- During development in serverless-app-template, use @serverless-app/cdk-aspects for local testing`
- Import statements follow the pattern:
typescript`
import { TableSettingsAspect, TagsAspect, addAspects } from '@serverless-app/cdk-aspects';
2. Production Usage:
- The serverless-app-template bootstrap process will automatically:
- Update dependencies to use @flipdish/cdk-aspects
- Replace import statements accordingly
- Remove the local aspects package
For all other projects, simply install and import @flipdish/cdk-aspects as shown in the Installation and Usage sections above.
You can verify the aspects are working correctly by checking your CloudFormation template. Here's an example using Jest/Vitest:
`typescript
import { Template } from 'aws-cdk-lib/assertions';
import { App } from 'sst/constructs';
describe('DynamoDB checks', () => {
it('All tables have billing mode PAY_PER_REQUEST', () => {
template.allResourcesProperties('AWS::DynamoDB::Table', {
BillingMode: 'PAY_PER_REQUEST',
});
});
it('All tables have point in time recovery enabled', () => {
template.allResourcesProperties('AWS::DynamoDB::Table', {
PointInTimeRecoverySpecification: {
PointInTimeRecoveryEnabled: true,
},
});
});
it('All tables should have RETAIN removal policy in production but DELETE in dev', () => {
checkTableDeletionPolicy(template, 'Delete');
checkTableDeletionPolicy(prodStageTemplate, 'Retain');
});
});
``
MIT
This package is maintained in the serverless-app-template repository.