-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-setup.yaml
67 lines (66 loc) · 2.03 KB
/
ec2-setup.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Description: ' This template creates an Amazon EC2 instance and an Elastic IP Address.
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: t2.micro
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: must be the name of an existing EC2 KeyPair.
Default: baws.admin
AMI:
Description: AMI id of Ubuntu 14.04
Type: String
Default: 'ami-f0f8d695'
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
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 IP CIDR range of the form x.x.x.x/x.
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData: !Base64
Fn::Join:
- ''
- - IPAddress=
- !Ref 'IPAddress'
InstanceType: !Ref 'InstanceType'
SecurityGroups:
- !Ref 'InstanceSecurityGroup'
KeyName: !Ref 'KeyName'
ImageId: !Ref AMI
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: '80'
ToPort: '80'
CidrIp: !Ref 'SSHLocation'
- IpProtocol: "tcp"
FromPort: '22'
ToPort: '22'
CidrIp: !Ref 'SSHLocation'
IPAddress:
Type: AWS::EC2::EIP
IPAssoc:
Type: AWS::EC2::EIPAssociation
Properties:
InstanceId: !Ref 'EC2Instance'
EIP: !Ref 'IPAddress'
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref 'EC2Instance'
InstanceIPAddress:
Description: IP address of the newly created EC2 instance
Value: !Ref 'IPAddress'