Each entry under Resources has a logical ID, a Type from the registry and Properties defined by that type's schema (Registry and Providers), plus optional attributes: Condition, DependsOn, DeletionPolicy, UpdateReplacePolicy (Deletion Policies), Metadata, and CreationPolicy/UpdatePolicy for a few types. A template may declare up to 500 resources.
Resources:
BooksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub booknest-${Stage}-${TableSuffix}
BillingMode: !FindInMap [StageSettings, !Ref Stage, BillingMode]
ProvisionedThroughput: !If
- IsProd
- {ReadCapacityUnits: !Ref ReadCapacity, WriteCapacityUnits: 5}
- !Ref AWS::NoValue
AttributeDefinitions: [{AttributeName: id, AttributeType: N}]
KeySchema: [{AttributeName: id, KeyType: HASH}]
FrontEndBucket:
Type: AWS::S3::Bucket
AccessLogs:
Type: AWS::Logs::LogGroup
Condition: IsProd
Properties:
LogGroupName: !Sub /booknest/${Stage}/access
RetentionInDays: !FindInMap [StageSettings, !Ref Stage, LogRetentionDays]Deploy one stack per stage from the same file:
cfn-lint booknest-data.yaml && echo "cfn-lint: no findings"
aws cloudformation deploy --stack-name booknest-data-dev --template-file booknest-data.yaml
aws cloudformation deploy --stack-name booknest-data-prod --template-file booknest-data.yaml \
--parameter-overrides Stage=prod ReadCapacity=10
for s in dev prod; do aws cloudformation describe-stack-resources --output text \
--stack-name booknest-data-$s --query 'StackResources[].LogicalResourceId'; done
aws dynamodb describe-table --table-name booknest-prod-books --output text \
--query 'Table.ProvisionedThroughput.ReadCapacityUnits'Output
cfn-lint: no findings Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - booknest-data-dev Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - booknest-data-prod BooksTable FrontEndBucket AccessLogs BooksTable FrontEndBucket 10
Dev has two resources, prod three, and only prod's table has ten read units. Building the table name from parameters keeps the stages apart in one account.