Blog 0.8: Creating AWS DynamoDB Table using CloudFormation
Cloudformation DynamoDB Table
Cloudformation
AWS Cloudformation is a service that gives developers and businesses an easy way to create a collection of related AWS and third-party resources, and provision manage them in a an orderly and predictable fashion.
Benifitst of using Cloudformation:
- Simplify infrastructure management
- It allows to quickly replicate your infrastructure
- It allows to easily control and track changes to your infrastructure
CloudFormation Template
A cloudformation template requires to be in JSON format text file or in YML format. In this text file format, you need to describe your AWS infrastructure. Templates can include several major sections:
- AWS TemplateFormatVersion
- Description
- Metadata
- Parameters
- Mappings
- Conditions
- Resources
- Outputs
DynamoDB Table
In this example, I will demonstrate a cloud formation template to create a AWS DynamoDB table with two attributes: ArtistName, AlbumName By creating a file on yml format we can upload as the stack on the AWS cloudformation service section.
AWSTemplateFormatVersion: "2010-09-09"
Resources:
myDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: "ArtistName"
AttributeType: "S"
-
AttributeName: "AlbumName"
AttributeType: "S"
KeySchema:
-
AttributeName: "ArtistName"
KeyType: "HASH"
-
AttributeName: "AlbumName"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
TableName: "Artist_DB"
In the above template, resource type identifies the type of resources that you are declaring. Here, you will define the resource as AWS::DynamoDB::Table and as well as the attributes.