@flipdish/cdk-aspects
v0.13.0
Published
CDK Aspects for Flipdish serverless applications
Keywords
Readme
@flipdish/cdk-aspects
CDK Aspects for Flipdish Serverless Applications that provide consistent AWS resource configuration and tagging across our infrastructure.
Installation
npm install @flipdish/cdk-aspectsUsage
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:
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;Available Aspects
TagsAspect
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.
new TagsAspect(serviceName, teamName)TableSettingsAspect
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)
new TableSettingsAspect(stage)Development Workflow (serverless-app-template only)
This section is only relevant if you are working within the serverless-app-template repository, where this package is maintained.
Local Development:
- During development in serverless-app-template, use
@serverless-app/cdk-aspectsfor local testing - Import statements follow the pattern:
import { TableSettingsAspect, TagsAspect, addAspects } from '@serverless-app/cdk-aspects';
- During development in serverless-app-template, use
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
- Update dependencies to use
- The serverless-app-template bootstrap process will automatically:
For all other projects, simply install and import @flipdish/cdk-aspects as shown in the Installation and Usage sections above.
Testing
You can verify the aspects are working correctly by checking your CloudFormation template. Here's an example using Jest/Vitest:
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');
});
});License
MIT
Contributing
This package is maintained in the serverless-app-template repository.
