AWS cloud formation is a model that helps to design and implement the AWS services.We can create a template which describes the AWS resources which is needs to be build (ex: EC2 instances and RDS services ) and AWS cloud formation takes care of its implementation. Also we don't need to individually create and configure AWS resources and figure out what dependent on what , cloudformation will figure out that and implement it
1. Format version ( optional)
This describes AWS cloudformation version that the template confirms to
2. Description ( optional )
A text that describes the template , this will alays follow the template format version session
3. Parameters
Specifies the values that you are passing with the template at run time. (when you create or update the stack .
4. Mappings (optional)
Mappings of the keys and its respective values are used to specify conditional parameter values. We can match a key to a corresponding value by using Fn::FindInMap function
5.Conditions
Defines conditions that control whether certain resources are created or whether
certain resource properties are assigned a value during stack creation or update. For
example, you could conditionally create a resource that depends on whether the
stack is for a production or test environment.
6. Resources
Specifies the stack resources and their properties, such as an Amazon Elastic
Compute Cloud instance or an Amazon Simple Storage Service bucket.
7. Outputs
Describes the values that are returned whenever you view your stack's properties.
{"AWSTemplateFormatVersion" : "2010-09-09",
{
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"KeyName" : "mykey",
"ImageId" : "ami-006b0447cf00d6804"
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"SecurityGroupIngress" : [
{ "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" },
{ "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" }
]
}
},
"ElasticLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties" : {
"AvailabilityZones" : { "Fn::GetAZs" : "" },
"Instances" : [ { "Ref" : "EC2Instance" } ],
"Listeners" : [ {
"LoadBalancerPort" : "80",
"InstancePort" : "80",
"Protocol" : "HTTP"
} ],
"HealthCheck" : {
"Target" : { "Fn::Join" : [ "", ["HTTP:", "80", "/"] ] },
"HealthyThreshold" : "3",
"UnhealthyThreshold" : "5",
"Interval" : "30",
"Timeout" : "5"
}
}
}
}
}
}
****************************************************************************
No let's upload the template to a stack and test
1. Select the cloudformation from the service list
2. Create the new stack and select the stack file which you have created above
3. Specify the stack name , in this case i have mentioned as unixchipstack
4. You can tag the stack for identification purpose
5. Once you review and upload the stack you can see new EC2 instance is created as below
If any error's in the stack template same can be highlighted in event tab and according to that e have to troubleshoot
AWS Cloudformation Structure
1. Format version ( optional)
This describes AWS cloudformation version that the template confirms to
2. Description ( optional )
A text that describes the template , this will alays follow the template format version session
3. Parameters
Specifies the values that you are passing with the template at run time. (when you create or update the stack .
4. Mappings (optional)
Mappings of the keys and its respective values are used to specify conditional parameter values. We can match a key to a corresponding value by using Fn::FindInMap function
5.Conditions
Defines conditions that control whether certain resources are created or whether
certain resource properties are assigned a value during stack creation or update. For
example, you could conditionally create a resource that depends on whether the
stack is for a production or test environment.
6. Resources
Specifies the stack resources and their properties, such as an Amazon Elastic
Compute Cloud instance or an Amazon Simple Storage Service bucket.
7. Outputs
Describes the values that are returned whenever you view your stack's properties.
Cloudformation template
This cloud formation template will create a EC2 instance and add them to a new load balancer
**********************************************************************
{
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],
"KeyName" : "mykey",
"ImageId" : "ami-006b0447cf00d6804"
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"SecurityGroupIngress" : [
{ "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" },
{ "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" }
]
}
},
"ElasticLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties" : {
"AvailabilityZones" : { "Fn::GetAZs" : "" },
"Instances" : [ { "Ref" : "EC2Instance" } ],
"Listeners" : [ {
"LoadBalancerPort" : "80",
"InstancePort" : "80",
"Protocol" : "HTTP"
} ],
"HealthCheck" : {
"Target" : { "Fn::Join" : [ "", ["HTTP:", "80", "/"] ] },
"HealthyThreshold" : "3",
"UnhealthyThreshold" : "5",
"Interval" : "30",
"Timeout" : "5"
}
}
}
}
}
}
****************************************************************************
No let's upload the template to a stack and test
1. Select the cloudformation from the service list
2. Create the new stack and select the stack file which you have created above
3. Specify the stack name , in this case i have mentioned as unixchipstack
4. You can tag the stack for identification purpose
5. Once you review and upload the stack you can see new EC2 instance is created as below
If any error's in the stack template same can be highlighted in event tab and according to that e have to troubleshoot
ReplyDeleteThis is an amazing blog, thank you so much for sharing such valuable information with us.
Workday Integration Training
Workday Integration Online Training