Created
April 19, 2015 18:40
-
-
Save klang/8249e0f563cdd3bc5fd0 to your computer and use it in GitHub Desktop.
A CloudFormation test template to create a VPC with a public subnet and spin up a internet connected instance inside of it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "Building a VPC from scratch with CloudFormation", | |
"Mappings": { | |
"SubnetConfig": { | |
"VPC": { "CIDR": "10.0.0.0/16" }, | |
"Public": { "CIDR": "10.0.0.0/24" } | |
}, | |
"RegionMap" : { | |
"eu-west-1": { "AMI" : "ami-8e987ef9" } | |
} | |
}, | |
"Resources": { | |
"VPC": { | |
"Type" : "AWS::EC2::VPC", | |
"Properties" : { | |
"CidrBlock" : { "Fn::FindInMap": ["SubnetConfig", "VPC", "CIDR"] }, | |
"EnableDnsSupport" : "true", | |
"EnableDnsHostnames": "true", | |
"Tags" : [ { "Key": "Application", "Value": { "Ref": "AWS::StackName"}}, | |
{ "Key": "Network", "Value": "Public"} | |
] | |
} | |
}, | |
"PublicSubnet": { | |
"Type" : "AWS::EC2::Subnet", | |
"Properties" : { | |
"CidrBlock" : { "Fn::FindInMap": ["SubnetConfig", "Public", "CIDR"] }, | |
"Tags" : [ { "Key": "Application", "Value": { "Ref": "AWS::StackName"}}, | |
{ "Key": "Network", "Value": "Public"} | |
], | |
"VpcId" : { "Ref" : "VPC" } | |
} | |
}, | |
"InternetGateway": { | |
"Type" : "AWS::EC2::InternetGateway" | |
}, | |
"GatewayToInternet": { | |
"Type" : "AWS::EC2::VPCGatewayAttachment", | |
"Properties" : { | |
"InternetGatewayId" : { "Ref": "InternetGateway" }, | |
"VpcId" : { "Ref": "VPC" } | |
} | |
}, | |
"PublicRouteTable": { | |
"Type" : "AWS::EC2::RouteTable", | |
"Properties" : { | |
"VpcId" : { "Ref": "VPC" } | |
} | |
}, | |
"PublicRoute": { | |
"Type" : "AWS::EC2::Route", | |
"DependsOn": "GatewayToInternet", | |
"Properties" : { | |
"DestinationCidrBlock" : "0.0.0.0/0", | |
"GatewayId" : { "Ref": "InternetGateway"}, | |
"RouteTableId" : { "Ref": "PublicRouteTable" } | |
} | |
}, | |
"PublicSubnetRouteTableAssociation": { | |
"Type" : "AWS::EC2::SubnetRouteTableAssociation", | |
"Properties" : { | |
"RouteTableId" : { "Ref": "PublicRouteTable" }, | |
"SubnetId" : { "Ref": "PublicSubnet" } | |
} | |
}, | |
"PublicInstance": { | |
"Type" : "AWS::EC2::Instance", | |
"DependsOn": "GatewayToInternet", | |
"Properties" : { | |
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}, | |
"InstanceType" : "t1.micro", | |
"NetworkInterfaces" : [ { "AssociatePublicIpAddress": "true", | |
"DeviceIndex": "0", | |
"DeleteOnTermination": "true", | |
"SubnetId" : { "Ref": "PublicSubnet" } } ] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment