cloudformation_template.json•2.24 kB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Example CloudFormation template for a simple EC2 instance",
"Parameters": {
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access",
"Type": "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription": "must be the name of an existing EC2 KeyPair."
},
"InstanceType": {
"Description": "EC2 instance type",
"Type": "String",
"Default": "t2.micro",
"AllowedValues": ["t2.micro", "t2.small", "t2.medium"],
"ConstraintDescription": "must be a valid EC2 instance type."
}
},
"Resources": {
"EC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"InstanceType": { "Ref": "InstanceType" },
"SecurityGroups": [{ "Ref": "InstanceSecurityGroup" }],
"KeyName": { "Ref": "KeyName" },
"ImageId": "ami-0c55b159cbfafe1f0",
"Tags": [
{ "Key": "Name", "Value": "ExampleInstance" },
{ "Key": "Environment", "Value": "Development" }
]
}
},
"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"
}
]
}
}
},
"Outputs": {
"InstanceId": {
"Description": "InstanceId of the newly created EC2 instance",
"Value": { "Ref": "EC2Instance" }
},
"AZ": {
"Description": "Availability Zone of the newly created EC2 instance",
"Value": { "Fn::GetAtt": ["EC2Instance", "AvailabilityZone"] }
},
"PublicDNS": {
"Description": "Public DNSName of the newly created EC2 instance",
"Value": { "Fn::GetAtt": ["EC2Instance", "PublicDnsName"] }
},
"PublicIP": {
"Description": "Public IP address of the newly created EC2 instance",
"Value": { "Fn::GetAtt": ["EC2Instance", "PublicIp"] }
}
}
}