Creating a table using a CloudFormation template

We will see the components of the CloudFormation template needed for this recipe. The completed template file is available with the code files.

  1. Start creating the CloudFormation template by defining the template format, the version, and a description:
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Your First DynamoDB Table
  1. Define the Resources section with the DynamoDB Table type:
Resources:
MyFirstTable:
Type: AWS::DynamoDB::Table
  1. Define the properties section with the essential properties: TableName, ProvisionedThroughput, KeySchema, and AttributeDefinitions:
Properties:
TableName: my_table
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
KeySchema:
-
AttributeName: id
KeyType: HASH
-
AttributeName: dateandtime
KeyType: RANGE
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
-
AttributeName: dateandtime
AttributeType: N
Properties and their values are the same as we saw with the AWS CLI commands earlier. You can use the AWS CLI dynamodb command actions list-tables and describe-table to check the created table.
  1. Update the table properties with the CloudFormation template:

Change ReadCapacityUnits and WriteCapacityUnits in the template to 5 for each. You can then update the stack using the aws cloudformation update-stack CLI command:

aws cloudformation update-stack 
--stack-name myteststack
--template-body file://resources/your-first-dynamodb-table-cf-template-updated.yml
--region us-east-1
--profile admin
Whenever an update is made, CloudFormation compares the template with the existing stack and updates only those resources that are changed. This is the first time we are using the update-stack action in this book. 
  1. Verify the table update using the aws dynamodb describe-table CLI command. 
  2. Delete the stack using the aws cloudformation delete-stack CLI command. As mentioned earlier, the other recipes in the chapter use this table, so if you are planning to continue with other recipes now, you may delete the table after completing them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72