forked from AHinMaine/AWSCloudFormation-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EC2InstanceWithEBSVolumeConditionalIOPs.template
170 lines (145 loc) · 7.05 KB
/
EC2InstanceWithEBSVolumeConditionalIOPs.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template EC2InstanceWithEBSVolumeConditionalIOPs: Example to show how to create an EC2 instance with an optionally attached volume. The instance is EBS Optimized and the volume is a PIOPs volume if the EC2 instance type supports it. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters" : {
"InstanceType" : {
"Description" : "WebServer EC2 instance type",
"Type" : "String",
"Default" : "m1.small",
"AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m3.xlarge","m3.2xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge","hi1.4xlarge","hs1.8xlarge"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the web server",
"Type" : "String"
},
"SSHFrom": {
"Description": "Lockdown SSH access to the bastion host (default can be accessed from anywhere)",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid CIDR range of the form x.x.x.x/x."
},
"EBSVolumeDeviceName" : {
"Description" : "Device name to attach an EBS volume (Default no EBS volume attached)",
"Type" : "String",
"Default" : "No Volume"
},
"VolumeSize" : {
"Description" : "Size of the EBS volume if attached",
"Type" : "Number",
"Default" : "100",
"MinValue" : "1",
"MaxValue" : "1000"
},
"IOPs" : {
"Description" : "Provisioned IOPs for EBS volume if supported by the instance type",
"Type" : "Number",
"Default" : "100",
"MinValue" : "1",
"MaxValue" : "30000"
}
},
"Mappings" : {
"InstanceConfig" : {
"t1.micro" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"m1.small" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"m1.medium" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"m1.large" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"m1.xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"m3.xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"m3.2xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"m2.xlarge" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"m2.2xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"m2.4xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"c1.medium" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"c1.xlarge" : { "Arch" : "PV64", "EBSOptimized" : "true" },
"g2.2xlarge" : { "Arch" : "GPU64", "EBSOptimized" : "true" },
"cc2.8xlarge" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"cr1.8xlarge" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"cg1.4xlarge" : { "Arch" : "GPU64", "EBSOptimized" : "false" },
"hi1.4xlarge" : { "Arch" : "PV64", "EBSOptimized" : "false" },
"hs1.8xlarge" : { "Arch" : "PV64", "EBSOptimized" : "false" }
},
"AWSRegionArch2AMI" : {
"us-east-1" : { "PV64" : "ami-35792c5c", "HVM64" : "ami-69792c00", "GPU64" : "ami-7f792c16" },
"us-west-2" : { "PV64" : "ami-d03ea1e0", "HVM64" : "ami-e43ea1d4", "GPU64" : "NOT_YET_SUPPORTED" },
"us-west-1" : { "PV64" : "ami-687b4f2d", "HVM64" : "ami-4e7b4f0b", "GPU64" : "NOT_YET_SUPPORTED" },
"eu-west-1" : { "PV64" : "ami-149f7863", "HVM64" : "ami-209f7857", "GPU64" : "ami-2c9f785b" },
"ap-southeast-1" : { "PV64" : "ami-14f2b946", "HVM64" : "ami-6af2b938", "GPU64" : "NOT_YET_SUPPORTED" },
"ap-southeast-2" : { "PV64" : "ami-a148d59b", "HVM64" : "ami-a948d593", "GPU64" : "NOT_YET_SUPPORTED" },
"ap-northeast-1" : { "PV64" : "ami-3561fe34", "HVM64" : "ami-0961fe08", "GPU64" : "NOT_YET_SUPPORTED" },
"sa-east-1" : { "PV64" : "ami-9f6ec982", "HVM64" : "ami-9d6ec980", "GPU64" : "NOT_YET_SUPPORTED" },
"us-gov-west-1" : { "PV64" : "ami-cdef8bee", "HVM64" : "ami-cfef8bec", "GPU64" : "NOT_YET_SUPPORTED" }
}
},
"Conditions" : {
"IsEBSOptimized" : { "Fn::Equals" : [ { "Fn::FindInMap" : [ "InstanceConfig", { "Ref" : "InstanceType" }, "EBSOptimized" ]}, "true" ] },
"AttachVolume" : { "Fn::Not" : [{ "Fn::Equals" : [ { "Ref" : "EBSVolumeDeviceName" }, "No Volume" ]}]}
},
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, { "Fn::FindInMap" : [ "InstanceConfig", { "Ref" : "InstanceType" }, "Arch" ] } ] },
"KeyName" : { "Ref" : "KeyName" },
"InstanceType" : { "Ref" : "InstanceType" },
"SecurityGroups" : [{ "Ref" : "Ec2SecurityGroup" }],
"EbsOptimized" : { "Fn::If" : ["IsEBSOptimized", "true", "false" ]}
}
},
"Ec2SecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "HTTP and SSH access",
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22", "ToPort" : "22",
"CidrIp" : { "Ref" : "SSHFrom" }
} ]
}
},
"EBSVolume": {
"Type": "AWS::EC2::Volume",
"Condition" : "AttachVolume",
"Properties": {
"Size": { "Ref" : "VolumeSize" },
"AvailabilityZone": { "Fn::GetAtt": [ "EC2Instance", "AvailabilityZone"] },
"VolumeType" : { "Fn::If" : ["IsEBSOptimized", "io1", {"Ref" : "AWS::NoValue"}]},
"Iops" : { "Fn::If" : ["IsEBSOptimized", { "Ref" : "IOPs" }, {"Ref" : "AWS::NoValue"}]}
}
},
"EBSVolumeAttachment" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Condition" : "AttachVolume",
"Properties" : {
"Device" : { "Ref" : "EBSVolumeDeviceName" },
"InstanceId" : { "Ref" : "EC2Instance" },
"VolumeId" : { "Ref" : "EBSVolume" }
}
}
},
"Outputs" : {
"Instance" : {
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PublicDnsName" ] },
"Description" : "DNS Name of the newly created EC2 instance"
},
"Device" : {
"Condition" : "AttachVolume",
"Value" : { "Ref" : "EBSVolumeDeviceName" },
"Description" : "Device name for the attached volume"
},
"EBSOptimized" : {
"Condition" : "AttachVolume",
"Value" : { "Fn::FindInMap" : [ "InstanceConfig", { "Ref" : "InstanceType" }, "EBSOptimized" ]},
"Description" : "Is the attached volume a PIOPs volume"
},
"IOPs" : {
"Condition" : "IsEBSOptimized",
"Value" : { "Ref" : "IOPs" },
"Description" : "IOPs configured for attached volume"
}
}
}