-
Notifications
You must be signed in to change notification settings - Fork 134
/
s3gateway.yaml
263 lines (263 loc) · 7.42 KB
/
s3gateway.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
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
NewBucketName:
Default: <ENTER_RANDOM_BUCKET_NAME_HERE>
Description: S3 Bucket Name
Type: String
Subnet1:
Default: <ENTER_YOUR_VALUE_HERE>
Description: ID of the first subnet to be used for resources
Type: String
Subnet2:
Default: <ENTER_YOUR_VALUE_HERE>
Description: ID of the second subnet to be used for resources
Type: String
VpcId:
Default: <ENTER_YOUR_VALUE_HERE>
Description: ID of the VPC to be used for resources
Type: String
ContainerName:
Default: s3gateway
Description: Name of the NGINX Container. No need to change this
Type: String
ResourceNamePrefix:
Default: nginx-s3-gateway
Description: Common prefix used for resource names. No need to change this
Type: String
Outputs:
PublicDNS:
Description: DNS name of load balancer
Value: !GetAtt 'ALB.DNSName'
Resources:
ALB:
Properties:
Name: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- alb
SecurityGroups:
- !GetAtt 'S3GatewaySG.GroupId'
SubnetMappings:
- SubnetId: !Ref 'Subnet1'
- SubnetId: !Ref 'Subnet2'
Type: application
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
ALBHttpListener:
Properties:
DefaultActions:
- ForwardConfig:
TargetGroups:
- TargetGroupArn: !Ref 'ALBTargetGroup'
Type: forward
LoadBalancerArn: !Ref 'ALB'
Port: 80
Protocol: HTTP
Type: AWS::ElasticLoadBalancingV2::Listener
ALBTargetGroup:
Properties:
Name: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- log-group
Port: 80
Protocol: HTTP
ProtocolVersion: HTTP1
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '150'
TargetType: ip
VpcId: !Ref 'VpcId'
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Cluster:
Properties:
ClusterName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- cluster
Type: AWS::ECS::Cluster
ECSLogGroup:
Properties:
LogGroupName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- logs
RetentionInDays: 14
Type: AWS::Logs::LogGroup
ECSTaskExecutionPolicy:
Properties:
PolicyDocument:
Statement:
- Action:
- logs:CreateLogStream
- logs:CreateLogGroup
- logs:PutLogEvents
Effect: Allow
Resource:
- '*'
Version: '2012-10-17'
PolicyName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- ecs-task-execution-policy
Roles:
- !Ref 'ECSTaskExecutionRole'
Type: AWS::IAM::Policy
ECSTaskExecutionRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Version: '2012-10-17'
Description: An IAM role to enable ECS agents to perform AWS operations such as creating CloudWatch logs.
RoleName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- ecs-task-execution-role
Type: AWS::IAM::Role
ECSTaskPolicy:
Properties:
PolicyDocument:
Statement:
- Action:
- s3:GetObject
- s3:ListBucket
Effect: Allow
Resource:
- !Sub
- arn:aws:s3:::${bucketName}/*
- bucketName: !Ref 'NewBucketName'
- !Sub
- arn:aws:s3:::${bucketName}
- bucketName: !Ref 'NewBucketName'
Version: '2012-10-17'
PolicyName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- ecs-task-policy
Roles:
- !Ref 'ECSTaskRole'
Type: AWS::IAM::Policy
ECSTaskRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Version: '2012-10-17'
Description: An IAM role to enable ECS containers to perform AWS operations such as accessing S3 buckets.
RoleName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- ecs-task-role
Type: AWS::IAM::Role
S3Bucket:
Properties:
BucketName: !Ref 'NewBucketName'
Type: AWS::S3::Bucket
S3GatewaySG:
Properties:
GroupDescription: Security group for NGINX S3 Gateway Infra
GroupName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- sg
SecurityGroupEgress:
- CidrIp: '0.0.0.0/0'
Description: Allow all outbound IPv4 traffic
IpProtocol: '-1'
- CidrIpv6: ::/0
Description: Allow all outbound IPv6 traffic
IpProtocol: '-1'
SecurityGroupIngress:
- CidrIp: '0.0.0.0/0'
Description: Allow HTTP Traffic on 80
FromPort: 80
IpProtocol: tcp
ToPort: 80
- CidrIp: '0.0.0.0/0'
Description: Allow HTTPS Traffic on 443
FromPort: 443
IpProtocol: tcp
ToPort: 443
VpcId: !Ref 'VpcId'
Type: AWS::EC2::SecurityGroup
S3GatewayService:
DependsOn: ALBHttpListener
Properties:
Cluster: !Ref 'Cluster'
DesiredCount: 1
LaunchType: FARGATE
LoadBalancers:
- ContainerName: !Ref 'ContainerName'
ContainerPort: 80
TargetGroupArn: !Ref 'ALBTargetGroup'
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups:
- !GetAtt 'S3GatewaySG.GroupId'
Subnets:
- !Ref 'Subnet1'
- !Ref 'Subnet2'
ServiceName: !Join
- '-'
- - !Ref 'ResourceNamePrefix'
- service
TaskDefinition: !Ref 'TaskDefinition'
Type: AWS::ECS::Service
TaskDefinition:
DependsOn: S3Bucket
Properties:
ContainerDefinitions:
- Environment:
- Name: ALLOW_DIRECTORY_LIST
Value: 'true'
- Name: AWS_SIGS_VERSION
Value: '4'
- Name: S3_BUCKET_NAME
Value: !Ref 'S3Bucket'
- Name: S3_REGION
Value: !Ref 'AWS::Region'
- Name: S3_SERVER_PORT
Value: '443'
- Name: S3_SERVER_PROTO
Value: https
- Name: S3_SERVER
Value: !Join
- .
- - s3
- !Ref 'AWS::Region'
- amazonaws.com
- Name: S3_STYLE
Value: default
- Name: DEBUG
Value: 'false'
Image: ghcr.io/nginxinc/nginx-s3-gateway/nginx-oss-s3-gateway:latest-njs-oss
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref 'ECSLogGroup'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: ecs
Name: !Ref 'ContainerName'
PortMappings:
- ContainerPort: 80
HostPort: 80
Cpu: '1024'
ExecutionRoleArn: !GetAtt 'ECSTaskExecutionRole.Arn'
Family: !Ref 'ContainerName'
Memory: '2048'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
TaskRoleArn: !GetAtt 'ECSTaskRole.Arn'
Type: AWS::ECS::TaskDefinition