-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweek1a.yml
More file actions
112 lines (103 loc) · 2.86 KB
/
week1a.yml
File metadata and controls
112 lines (103 loc) · 2.86 KB
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
# A description of what your template does.
Description: My first VPC (10.0.0.0/16) with a public subnet (10.0.10.0/24).
# Parameters you can set in CloudFormation when you roll out your stack.
Parameters:
VPCCIDR:
Description: Please enter the IP range (CIDR notation) for this VPC.
Type: String
Default: 10.0.0.0/16
PublicSubnetCIDR:
Description: Please enter the IP range (CIDR notation) for the public subnet
Type: String
Default: 10.0.10.0/24
SSHKey:
Description: Please enter key name.
Type: String
Default: MyAWSKey
# The cloud resources your template is going to create.
Resources:
MyFirstVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VPCCIDR
Tags: # Good practice is to add tags!
- Key: Name
Value: Week1VPC
MyFirstSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref PublicSubnetCIDR
MapPublicIpOnLaunch: yes # Important! See documentation.
VpcId: !Ref MyFirstVPC
Tags:
- Key: Name
Value: Week1Subnet
MyInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: Week1Gateway
MyGatewayAttach:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref MyInternetGateway
VpcId: !Ref MyFirstVPC
MyFirstRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref MyFirstVPC
Tags:
- Key: Name
Value: Week1Table
MyRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref MyFirstRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref MyInternetGateway
MySubnetRouteAss:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref MyFirstRouteTable
SubnetId: !Ref MyFirstSubnet
MySG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Webserver SG
GroupName: Webserver SG
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: Week1SG
VpcId: !Ref MyFirstVPC
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
KeyName: !Ref SSHKey
ImageId: ami-033b95fb8079dc481
InstanceType: t2.micro
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
SubnetId: !Ref MyFirstSubnet
GroupSet:
- Ref: MySG
Tags:
- Key: Name
Value: Week1EC2
UserData:
Fn::Base64: |
#!/bin/bash
amazon-linux-extras install nginx1 -y
echo "Lorem Ipsum enzo!" > /usr/share/nginx/html/index.html
systemctl enable nginx
systemctl start nginx