AWS最佳架构--VPC
以下代码为AWS云服务中CloudFormation的VPC模板,编写人:Xiong,2019年12月12日上传至本站。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"vpc": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref":"vpccidr"
},
"EnableDnsHostnames": "true",
"EnableDnsSupport": "true",
"Tags": [
{
"Key": "Name",
"Value": "vpc"
}
]
}
},
"pubnet1":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"0",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"pubnet1cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"pubnet1"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"pubnet2":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"1",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"pubnet2cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"pubnet2"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"webnet1":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"0",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"webnet1cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"webnet1"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"webnet2":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"1",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"webnet2cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"webnet2"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"dbnet1":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"0",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"dbnet1cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"dbnet1"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"dbnet2":{
"Type":"AWS::EC2::Subnet",
"Properties":{
"AvailabilityZone":{
"Fn::Select":[
"1",
{
"Fn::GetAZs":""
}
]
},
"CidrBlock":{
"Ref":"dbnet2cidr"
},
"Tags":[
{
"Key":"Name",
"Value":"dbnet2"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"table1":{
"Type":"AWS::EC2::RouteTable",
"Properties":{
"Tags":[
{
"Key":"Name",
"Value":"table1"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"table2":{
"Type":"AWS::EC2::RouteTable",
"Properties":{
"Tags":[
{
"Key":"Name",
"Value":"table2"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"table3":{
"Type":"AWS::EC2::RouteTable",
"Properties":{
"Tags":[
{
"Key":"Name",
"Value":"table3"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"igw":{
"Type":"AWS::EC2::InternetGateway",
"Properties":{}
},
"igwvpc":{
"Type":"AWS::EC2::VPCGatewayAttachment",
"Properties":{
"InternetGatewayId":{
"Ref":"igw"
},
"VpcId":{
"Ref":"vpc"
}
}
},
"natgateway1":{
"Type":"AWS::EC2::NatGateway",
"Properties":{
"AllocationId":{
"Fn::GetAtt":[
"eip1",
"AllocationId"
]
},
"SubnetId":{
"Ref":"pubnet1"
}
}
},
"natgateway2":{
"Type":"AWS::EC2::NatGateway",
"Properties":{
"AllocationId":{
"Fn::GetAtt":[
"eip2",
"AllocationId"
]
},
"SubnetId":{
"Ref":"pubnet2"
}
}
},
"eip1":{
"Type":"AWS::EC2::EIP",
"Properties":{}
},
"eip2":{
"Type":"AWS::EC2::EIP",
"Properties":{}
},
"RouteTablepubnet1":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"pubnet1"
},
"RouteTableId":{
"Ref":"table1"
}
}
},
"RouteTablepubnet2":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"pubnet2"
},
"RouteTableId":{
"Ref":"table1"
}
}
},
"RouteTablewebnet3":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"webnet1"
},
"RouteTableId":{
"Ref":"table2"
}
}
},
"RouteTablewebnet4":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"webnet2"
},
"RouteTableId":{
"Ref":"table3"
}
}
},
"RouteTabledbnet5":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"dbnet1"
},
"RouteTableId":{
"Ref":"table2"
}
}
},
"RouteTabledbnet6":{
"Type":"AWS::EC2::SubnetRouteTableAssociation",
"Properties":{
"SubnetId":{
"Ref":"dbnet2"
},
"RouteTableId":{
"Ref":"table3"
}
}
},
"route1":{
"Type":"AWS::EC2::Route",
"Properties":{
"DestinationCidrBlock":"0.0.0.0/0",
"GatewayId":{
"Ref":"igw"
},
"RouteTableId":{
"Ref":"table1"
}
}
},
"route2":{
"Type":"AWS::EC2::Route",
"Properties":{
"DestinationCidrBlock":"0.0.0.0/0",
"NatGatewayId":{
"Ref":"natgateway1"
},
"RouteTableId":{
"Ref":"table2"
}
}
},
"route3":{
"Type":"AWS::EC2::Route",
"Properties":{
"DestinationCidrBlock":"0.0.0.0/0",
"NatGatewayId":{
"Ref":"natgateway2"
},
"RouteTableId":{
"Ref":"table3"
}
}
},
"pubgroup":{
"Type":"AWS::EC2::SecurityGroup",
"Properties":{
"GroupDescription": "pubgroup",
"GroupName":"pubgroup",
"Tags":[
{
"Key":"Name",
"Value":"pubgroup"
}
],
"SecurityGroupIngress":[
{
"CidrIp":"0.0.0.0/0",
"FromPort":"80",
"IpProtocol":"tcp",
"ToPort":"80"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"webgroup":{
"Type":"AWS::EC2::SecurityGroup",
"Properties":{
"GroupDescription": "webgroup",
"GroupName":"webgroup",
"Tags":[
{
"Key":"Name",
"Value":"webgroup"
}
],
"SecurityGroupIngress":[
{
"SourceSecurityGroupId":{
"Ref":"pubgroup"
},
"FromPort":"80",
"IpProtocol":"tcp",
"ToPort":"80"
}
],
"VpcId":{
"Ref":"vpc"
}
}
},
"dbgroup":{
"Type":"AWS::EC2::SecurityGroup",
"Properties":{
"GroupName":"dbgroup",
"GroupDescription": "dbgroup",
"Tags":[
{
"Key":"Name",
"Value":"dbgroup"
}
],
"SecurityGroupIngress":[
{
"SourceSecurityGroupId":{
"Ref":"webgroup"
},
"FromPort":"3306",
"IpProtocol":"tcp",
"ToPort":"11211"
},
{
"SourceSecurityGroupId": {
"Ref": "webgroup"
},
"FromPort": {
"Ref": "cacheport"
},
"ToPort": {
"Ref": "cacheport"
},
"IpProtocol": "tcp"
}
],
"VpcId":{
"Ref":"vpc"
}
}
}
},
"Parameters":{
"vpccidr":{
"Type":"String",
"Default":"10.1.0.0/16"
},
"pubnet1cidr":{
"Type":"String",
"Default":"10.1.1.0/24"
},
"pubnet2cidr":{
"Type":"String",
"Default":"10.1.2.0/24"
},
"webnet1cidr":{
"Type":"String",
"Default":"10.1.3.0/24"
},
"webnet2cidr":{
"Type":"String",
"Default":"10.1.4.0/24"
},
"dbnet1cidr":{
"Type":"String",
"Default":"10.1.5.0/24"
},
"dbnet2cidr":{
"Type":"String",
"Default":"10.1.6.0/24"
},
"cacheport":{
"Type":"String",
"Default":"11211"
}
},
"Outputs":{
"pubnet1id":{
"Value":{
"Ref":"pubnet1"
}
},
"pubnet2id":{
"Value":{
"Ref":"pubnet2"
}
},
"webnet1id":{
"Value":{
"Ref":"webnet1"
}
},
"webnet2id":{
"Value":{
"Ref":"webnet2"
}
},
"dbnet1id":{
"Value":{
"Ref":"dbnet1"
}
},
"dbnet2id":{
"Value":{
"Ref":"dbnet2"
}
},
"vpcid":{
"Value":{
"Ref":"vpc"
}
},
"pubgroupid":{
"Value":{
"Ref":"pubgroup"
}
},
"webgroupid":{
"Value":{
"Ref":"webgroup"
}
},
"dbgroupid":{
"Value":{
"Ref":"dbgroup"
}
}
}
}