forked from OpenWebinarsNet/curso-cloudformation
/
reto-elb.json
116 lines (116 loc) · 3.32 KB
/
reto-elb.json
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
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Grupo de Escalado con ELB",
"Parameters": {
"TipoInstancia": {
"Type": "String",
"Description": "Tipo de instancia",
"AllowedValues": [ "t2.micro", "t2.small" ],
"Default": "t2.micro"
},
"NumeroInstancias" : {
"Type": "String",
"Description": "Numero de instancias para el grupo de escalado",
"AllowedValues" : [ "1", "2" ],
"Default": "1"
},
"ParClave": {
"Type": "AWS::EC2::KeyPair::KeyName",
"Description": "Par de claves para acceder a la instancia",
"AllowedPattern" : ".+",
"ConstraintDescription": "Es obligatorio seleccionar un par de claves"
},
"ZonaDisponibilidad": {
"Type": "String",
"Description": "Zona de disponibilidad para los recursos (se usará la misma para todos)",
"AllowedPattern" : ".+",
"ConstraintDescription": "Es obligatorio escribir una zona de disponibilidad",
"Default": "us-east-2c"
}
},
"Resources": {
"LaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Metadata": {
"AWS::CloudFormation::Init": {
"config": {
"packages": {
"yum": {
"httpd": []
}
},
"services": {
"sysvinit": {
"httpd": {
"enabled": "true",
"ensureRunning": "true"
}
}
}
}
}
},
"Properties": {
"ImageId": "ami-922914f7",
"InstanceType": { "Ref": "TipoInstancia" },
"KeyName": { "Ref": "ParClave" },
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[ "#!/bin/bash -xe\n",
"# Install the files and packages from the metadata\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ", { "Ref": "AWS::StackName" },
" --resource LaunchConfig",
" --region ", { "Ref": "AWS::Region" }, "\n"
]
]
}
}
}
},
"GrupoEscalado": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": [ { "Ref": "ZonaDisponibilidad" } ],
"LaunchConfigurationName": { "Ref" : "LaunchConfig" },
"MinSize": { "Ref": "NumeroInstancias" },
"MaxSize": { "Ref": "NumeroInstancias" },
"LoadBalancerNames": [ { "Ref": "Balanceador" } ],
}
},
"Balanceador": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"AvailabilityZones": [ { "Ref": "ZonaDisponibilidad" } ],
"Listeners": [
{
"LoadBalancerPort": "80",
"InstancePort": "80",
"Protocol": "TCP",
"InstanceProtocol" : "TCP"
}
],
"HealthCheck": {
"Target": "TCP:80",
"HealthyThreshold": "2",
"UnhealthyThreshold": "2",
"Interval": "10",
"Timeout": "5"
}
}
}
},
"Outputs": {
"URLBalanceador": {
"Description" : "Balanceador",
"Value" : {
"Fn::Join": [
"",
[ "http://", "Fn::GetAtt": [ "Balanceador", "DNSName" ] ]
]
}
}
}
}