-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionManager-EC2-CFT.yaml
87 lines (81 loc) · 2.26 KB
/
SessionManager-EC2-CFT.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
AWSTemplateFormatVersion: "2010-09-09"
Description: Pass user Data with EC2 instace
Parameters:
AvailabilityZone:
Type: AWS::EC2::AvailabilityZone::Name
Description: this will get availaibyt zone of account
Resources:
# Add Session Manager Access Role to EC2
SsmIamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ ec2.amazonaws.com ]
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
# Create InstaceProfile
ServerInstacneProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref SsmIamRole
Path: /
ServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for SSH and Port 80
SecurityGroupIngress:
- IpProtocol: tcp
ToPort: 80
FromPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
ToPort: 22
FromPort: 22
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: UserDataWithEc2
# Create Elastic IP
ElasticIP:
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref EC2UserDataInstance
Tags:
- Key: Name
Value: UserDataWithEc2
# EC2 Machine
EC2UserDataInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: !Ref AvailabilityZone
ImageId: ami-009d6802948d06e52
InstanceType: t2.micro
IamInstanceProfile: !Ref ServerInstacneProfile
SecurityGroups:
- !Ref ServerSecurityGroup
Tags:
- Key: Name
Value: UserDataWithEc2
# Install userData for starting Httpd
UserData:
Fn::Base64: |
#!/bin/bash
sudo su
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "Hello World from $(hostname -f)" > /var/www/html/index.html
Outputs:
PublicIp:
Value:
Fn::GetAtt:
- EC2UserDataInstance
- PublicIp
Description: Get Public IP of Instance