-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathopensearch_nginx.yaml
299 lines (278 loc) · 7.45 KB
/
opensearch_nginx.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
Description: This template will an OpenSearch Demo within a VPC with Subnets, Security Groups ...
Parameters:
# Ask the user for the name of the EC2
EC2KeyPairNameParameter:
Type: AWS::EC2::KeyPair::KeyName
Description: name of the key pair to ssh into the instance
Resources:
# -----------------
# VPC
# -----------------
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: '10.0.0.0/16'
Tags:
- Key: Name
Value: workshop vpc
# -----------------
# Internet Gateway
# -----------------
VPCInternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: workshop internet gateway
# Attach InternetGateway to VPC
AttachInternetGatewayVPC:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
InternetGatewayId:
Ref: VPCInternetGateway
VpcId:
Ref: VPC
# -----------------
# Subnets
# -----------------
#
# OS Subnet
#
OpenSearchSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.0.0.0/28'
AvailabilityZone: 'us-east-1a'
VpcId: !Ref VPC
Tags:
- Key: Name
Value: opensearch-subnet | us-east-1a
#
# EC2 Subnet
#
EC2Subnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: '10.0.2.0/28'
AvailabilityZone: 'us-east-1a'
VpcId: !Ref VPC
Tags:
- Key: Name
Value: ec2-subnet | us-east-1a
# -----------------
# Network Security Groups
# -----------------
#
# OS Security Group
#
OpenSearchSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: 'open search security group'
GroupDescription: 'open search security group'
VpcId: !Ref VPC
# Egress rules
SecurityGroupEgress:
- IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: '0.0.0.0/0'
Tags:
- Key: Name
Value: 'os security group'
# add a self reference ingress rule
OpenSearchSecurityGroupIngress1:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
# Ingress rules
GroupId: !Ref OpenSearchSecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !GetAtt OpenSearchSecurityGroup.GroupId
# add a ingress rule for traffic from EC2
OpenSearchSecurityGroupIngress2:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
# Ingress rules
GroupId: !Ref OpenSearchSecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !GetAtt EC2SecurityGroup.GroupId
#
# EC2 Security Group
#
EC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: 'ec2 security group'
GroupDescription: 'ec2 security group'
VpcId: !Ref VPC
# Egress rules
SecurityGroupEgress:
- IpProtocol: -1
FromPort: -1
ToPort: -1
CidrIp: '0.0.0.0/0'
Tags:
- Key: Name
Value: 'ec2 security group'
# Network Security Group + add a self reference ingress rule
EC2SecurityGroupGroupIngress:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
# Ingress rules
GroupId: !Ref EC2SecurityGroup
IpProtocol: -1
FromPort: -1
ToPort: -1
SourceSecurityGroupId: !GetAtt EC2SecurityGroup.GroupId
# -----------------
# OpenSearch domain
# -----------------
OpenSearchDomain:
Type: AWS::OpenSearchService::Domain
Properties:
DomainName: workshop-domain-vpc
EngineVersion: 'OpenSearch_1.3'
# Development configuration
ClusterConfig:
DedicatedMasterEnabled: false
InstanceCount: '1'
ZoneAwarenessEnabled: false
InstanceType: 'r6g.large.search'
EBSOptions:
EBSEnabled: true
VolumeSize: '20'
VolumeType: 'gp2'
# Node to node encrpytion must be enabled to use the advanced security options
NodeToNodeEncryptionOptions:
Enabled: true
# Encryption at rest must be ebabled to use the advanced security options
EncryptionAtRestOptions:
Enabled: true
# HTTPS must be required to use the advanced security options
DomainEndpointOptions:
EnforceHTTPS: true
# Create a master user with a pre-defined username and password
AdvancedSecurityOptions:
Enabled: true
InternalUserDatabaseEnabled: true
MasterUserOptions:
MasterUserName: 'OSMasterUser'
MasterUserPassword: 'AwS#OpenSearch1'
# Set an access policy open to any AWS resource
AccessPolicies:
Version: 2012-10-17
Statement:
Effect: 'Allow'
Principal:
AWS: '*'
Action: 'es:*'
Resource: '*'
# VPC
VPCOptions:
SecurityGroupIds:
- Ref: OpenSearchSecurityGroup
SubnetIds:
- Ref: OpenSearchSubnet
# -----------------
# IAM role
# -----------------
#
# EC2 IAM Role
#
EC2IAMRole:
Type: AWS::IAM::Role
Properties:
RoleName: 'Workshop_EC2'
Description: 'IAM role for EC2 instance'
# Trust relationships
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- 'sts:AssumeRole'
# Premissions
Policies:
# EC2 premissions
- PolicyName: ec2
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: 'ec2:*'
Resource: '*'
# IAM instance profile
EC2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles: [!Ref EC2IAMRole]
# -----------------
# EC2
# -----------------
EC2Server:
Type: AWS::EC2::Instance
Properties:
ImageId: 'ami-052efd3df9dad4825'
InstanceType: 't2.xlarge'
SubnetId: !Ref EC2Subnet
SecurityGroupIds:
- !Ref EC2SecurityGroup
KeyName: !Ref EC2KeyPairNameParameter
IamInstanceProfile: !Ref EC2InstanceProfile
Tags:
- Key: Name
Value: workshop-ec2
# -----------------
# Elastic IP
# -----------------
EC2ElasticIP:
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref EC2Server
# -----------------
# Route Table
# -----------------
VPCRouteTable:
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: workshop route table
VpcId: !Ref VPC
# add a route to the internet gateway
InternetGatewayRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref VPCRouteTable
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !Ref VPCInternetGateway
# associate route table with subnets (OpenSearchSubnet, EC2Subnet)
OpenSearchSubnetAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref VPCRouteTable
SubnetId: !Ref OpenSearchSubnet
EC2SubnetAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref VPCRouteTable
SubnetId: !Ref EC2Subnet
Outputs:
# OpenSearch domain
OSUserName:
Description: 'OpenSearch Dashboard Login UserName'
Value: 'OSMasterUser'
OSPassword:
Description: 'OpenSearch Dashboard Login Password'
Value: 'AwS#OpenSearch1'
EC2RDPIPAddress:
Description: 'IP Address to connect to EC2 via. RDP'
Value: !Ref EC2ElasticIP