amazon-dynamodbaws-cloudformationinfrastructure-as-codeserverless-architecture

DynamoDb in CloudFormation or not


I'm building a production level serverless application and I'm debating if I should put DynamoDb tables in CloudFormation or not. We are also using Aurora PostgreSQL and I read it is not recommended to use CloudFormation for that or if you do, then you need to use a completely different stack (not nested stack).

Currently our CloudFormation stack looks like this: Main Stack (builds Lambdas, ApiGateway) -> [Nested stack] Networking (VPCs, subnets, etc) based on environment

In your experience, what is recommended for CloudFormation and DynamoDb tables:

  1. Build DynamoDb tables manually and fully separately (no CloudFormation)
  2. Build a whole different CloudFormation stack (separate from any other stack)
  3. Build DynamoDb tables as a nested stack to the main existing stack
  4. Build DynamoDb tables right in the main stack

Looking for a design that will last and not require migrations or rebuilding tables.


Solution

  • Cloudformation can retain the table and tables data under any change. You can import the data to subsequent stacks of you wish.

    Many users like to decouple their data layer from the application layer as the application layer typically changes more frequent, but this approach is a personal choice, it's not required.

    So my educated recommendation is to use cloudformation to manage the table for sure, but it's totally dependent on you how you implement the specific stack.