Before I start - CloudFormation is by far one of the weirdest and coolest things to have come out of AWS. It took me some time to grasp it (and am still grasping) but mann its awesome for AWS users.
This CloudFormation template (available in AWS Website BTW) will setup an DynamoDb table.
As seen CloudFormation created the stack with the resource 'myDynamoDbTable'
Pre CloudFormation - (or all AWS posts to date in this blog) we had to create everything manually - either via AWS Console or AWS CLI. This meant each user running adhoc set of commands that they hoped were not having any unintended consequences.
Enter CloudFormation. With CloudFormation you can define all the AWS resources you want to create in a file. Specifically a JSON or YAML file. This file is what CloudFormation calls a template.
The file declares all the aws resources we need to create for your application. For example consider the below JSON template:
1 | {This template demonstrates creation of DynamoDB table.- optional when creating/updating stack"HashKeyElementName" : { 'myDynamoDBTable' is the Logical ID for the resource being created here"myDynamoDBTable" : { - the resource being created, can be referred in resources and outputs "TableName" : {
|
All the resources that we have listed here together form what is called a stack. In the above example the Stack is composed of a DynamoDb table. I will be using the AWS UI for this.
I uploaded the template file from local machine.The next step requires us to provide the name for the Stack. Also any parameters specified in template need to be provided here. The next couple of steps can be ignored now and I started the create stack step.
The output from template is the Stack Resource
We have the dynamo table ready and setup to use - Infrastructure as Code is achieved.




