Template Structure
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Web Application Stack",
"Parameters": {
"InstanceType": {
"Type": "String",
"Default": "t2.micro",
"AllowedValues": ["t2.micro", "t2.small", "t2.medium"]
}
},
"Resources": {
"WebServerInstance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"InstanceType": {"Ref": "InstanceType"},
"ImageId": "ami-0c55b159cbfafe1f0",
"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]
}
}
},
"Outputs": {
"WebsiteURL": {
"Description": "URL for the website",
"Value": {"Fn::GetAtt": ["WebServerInstance", "PublicDnsName"]}
}
}
}
Stack Management
# Create Stack
aws cloudformation create-stack \
--stack-name my-web-app \
--template-body file://template.json \
--parameters ParameterKey=InstanceType,ParameterValue=t2.small
# Update Stack
aws cloudformation update-stack \
--stack-name my-web-app \
--template-body file://template.json \
--parameters ParameterKey=InstanceType,ParameterValue=t2.medium