2023-09-18 03:08:34+00:00

Setting up cloud resources manually by clicking through the AWS Web Console is a major risk for production systems. It is impossible to replicate the configuration perfectly for staging or testing environments, and there is no version history. Infrastructure-as-Code (IaC) solves this by defining your resources in declarative code files.

Using AWS CloudFormation, we define our serverless queues, topics, DynamoDB tables, and Lambda permissions in a single JSON/YAML file.


1. Declaring a DynamoDB Table in CloudFormation

We specify key schemas, attribute definitions, and billing modes. The following snippet declares the main descriptions table with standard billing mode:

{
  "Type": "AWS::DynamoDB::Table",
  "Properties": {
    "TableName": "goseanto-part-number-descriptions",
    "AttributeDefinitions": [
      { "AttributeName": "PK", "AttributeType": "S" },
      { "AttributeName": "SK", "AttributeType": "S" }
    ],
    "KeySchema": [
      { "AttributeName": "PK", "KeyType": "HASH" },
      { "AttributeName": "SK", "KeyType": "RANGE" }
    ],
    "BillingMode": "PAY_PER_REQUEST"
  }
}

2. Deploying Stacks in CI/CD

During deployment, the CI/CD pipeline executes the AWS CLI command to validate and deploy the CloudFormation template as a stack:

aws cloudformation deploy --template-file CFN_TableCreation.json --stack-name cpunto-resources
This ensures that staging and production environments are identical in schema and permissions.