EMAIL SUPPORT

dclessons@dclessons.com

LOCATION

NZ

How to Create Template for CloudFormation

How to Create Template for CloudFormation

Posted on Jan 17, 2020 (0)

How to Create Template for CloudFormation

To use Cloud Formation stack , we have to create the Template which may be in JSON or YAMI format.

Task :

  • Create the JSON template for VPC.
  • Create the JSON template for Subnets
  • Create the JSON template for Internet gateway
  • Create the JSON template for NAT gateway

Steps:

Format for VPC:

{
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : String,
"EnableDnsSupport" : Boolean,
"EnableDnsHostnames" : Boolean,
"InstanceTenancy" : String,
"Tags" : [ Resource Tag, ... ]
}
}

Values to be supplied in VPC Template:

Example:

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"VPCTesting" : {
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : "10.1.0.0/16",
"EnableDnsSupport" : "false", "EnableDnsHostnames" : "false", "InstanceTenancy" : "dedicated",
"Tags" : [ {"Key" : "Name", "Value" : “VPC-Dev"} ]
}
}
}
}

Format for Subnet Creation:

{
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : String,
"CidrBlock" : String,
"MapPublicIpOnLaunch" : Boolean,
"Tags" : [ Resource Tag, ... ],
"VpcId" : String
}
}

Format for Internet Gateway:

{
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {
"Tags" : [ Resource Tag, ... ]
}
}

Example:

"InternetGateway" : {
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {
"Tags" : [ "Key" : "Name", "Value" : { "Ref" : "AWS::StackName"} ]
}
}

The format for Elastic IP :

{
"Type" : "AWS::EC2::EIP",
"Properties" : {
"InstanceId" : String,
"Domain" : String
}
}

Example:

"EIP" : {
"Type" : "AWS::EC2::EIP",
"Properties" : {
"Domain" : "vpc"
}
}

The format for NAT Gateway:

{
"Type" : "AWS::EC2::NatGateway",
"Properties" : {
"AllocationId" : String,
"SubnetId" : String
}
}

Example:

"NATGateway" : {
"Type" : "AWS::EC2::NatGateway",
"DependsOn": "VPCGatewayAttach",
"Properties" : {
"AllocationId" : { "Fn::GetAtt" : ["NATGatewayEIP", "AllocationId"]},
"SubnetId" : { "Ref" : "PublicSubnet"}
}
}

When ever a JSON script is ceated then it can be tested  weather it is in proper format or not:

Testing the JSON template

There are many tools available for JSON format testing, for example: https://jsonlint.com/.


Comment

    You are will be the first.

LEAVE A COMMENT

Please login here to comment.