原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://zhenhua2000.blog.51cto.com/3167594/1335468
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
|
{
"AWSTemplateFormatVersion"
:
"2010-09-09"
,
"Parameters"
: {
"KeyName"
: {
"Description"
:
"Name of an existing EC2 KeyPair to enable SSH access to the instance"
,
"Type"
:
"String"
}
},
"Resources"
: {
"MyInstance"
: {
"Type"
:
"AWS::EC2::Instance"
,
"Properties"
: {
"KeyName"
: {
"Ref"
:
"KeyName"
},
"ImageId"
:
"F17-x86_64-cfntools"
,
"InstanceType"
:
"m1.small"
,
"UserData"
: {
"Fn::Base64"
:
"80"
}
}
}
},
"Outputs"
: {
"InstanceIp"
: {
"Value"
: {
"Fn::Join"
: [
""
, [
"ssh ec2-user@"
,
{
"Fn::GetAtt"
: [
"MyInstance"
,
"PublicIp"
]}]]},
"Description"
:
"My ssh command"
}
}
}
|
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
|
Parameters:
ssh_key_name:
Type: String
Description:
ssh
keypair name
image_name:
Type: String
Description: The image to boot
Resources:
my_server:
Type: OS::Nova::Server
Properties:
flavor: m1.small
key_name: {
"Ref"
:
"ssh_key"
}
block_device_mapping:
device_name: vda
volume_id: {
"Ref"
:
"my_vol"
}
my_vol:
Type: OS::Cinder::Volume
Properties:
size: 20
image: {
"Ref"
:
"image_name"
}
Outputs:
server_ip:
Description: The server IP
Value: {
"Fn::GetAtt"
:
[
"my_server"
,
"first_address"
]}
|
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
|
Resources:
MEMAlarmHigh:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: Scale-up
if
MEM > 50%
for
1 minute
MetricName: MemoryUtilization
Namespace: system
/linux
Statistic: Average
Period:
'60'
EvaluationPeriods:
'1'
Threshold:
'50'
AlarmActions:
- {Ref: WebServerScaleUpPolicy}
Dimensions:
- Name: AutoScalingGroupName
Value: {Ref: WebServerGroup}
ComparisonOperator: GreaterThanThreshold
WebServerScaleUpPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName: {Ref: WebServerGroup}
Cooldown:
'60'
ScalingAdjustment:
'1'
WebServerGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones: {
'Fn::GetAZs'
:
''
}
LaunchConfigurationName: {Ref: LaunchConfig}
MinSize:
'1'
MaxSize:
'3'
LoadBalancerNames:
- {Ref: ElasticLoadBalancer}
ElasticLoadBalancer:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
...
LaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
...
Properties:
|