-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcloudformation.yml
222 lines (209 loc) · 6.38 KB
/
cloudformation.yml
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
AWSTemplateFormatVersion: '2010-09-09'
Description: |
Creates resources for StreamScale project.
Services include ECS cluster, Task Defination, SQS Queue, ECR Repo , S3 for temporary video storage, and a IAM role for access.
NOTE: You can change the architecture if using EC2 instead of FARGATE. Make sure to not mess with other settings.
Resources:
SQSQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub '${AWS::StackName}-queue'
SQSQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref SQSQueue
PolicyDocument:
Version: '2012-10-17'
Id: !Sub '${AWS::StackName}-sqs-policy'
Statement:
- Sid: SendUploadEvent
Effect: Allow
Principal:
Service: s3.amazonaws.com
Action: SQS:SendMessage
Resource: !GetAtt SQSQueue.Arn
Condition:
StringEquals:
aws:SourceAccount: !Ref 'AWS::AccountId'
ArnLike:
aws:SourceArn: !Sub 'arn:aws:s3:::${AWS::StackName}-bucket'
StringLike:
s3:object-key:
- '*.mp4'
- '*.avi'
- '*.mov'
- '*.wmv'
- '*.flv'
- '*.mkv'
- '*.webm'
- '*.m4v'
- '*.mpeg'
- '*.mpg'
- '*.3gp'
- '*.3g2'
- '*.mxf'
- '*.asf'
- '*.vob'
- Sid: AllowS3SendMessage
Effect: Allow
Principal:
Service: s3.amazonaws.com
Action: SQS:SendMessage
Resource: !GetAtt SQSQueue.Arn
S3Bucket:
Type: AWS::S3::Bucket
DependsOn: SQSQueuePolicy
Properties:
BucketName: !Sub '${AWS::StackName}-bucket'
NotificationConfiguration:
QueueConfigurations:
- Event: 's3:ObjectCreated:*'
Queue: !GetAtt SQSQueue.Arn
CorsConfiguration:
CorsRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- GET
- POST
- PUT
- DELETE
- HEAD
AllowedOrigins:
- "*"
IAMUser:
Type: AWS::IAM::User
Properties:
UserName: !Sub '${AWS::StackName}-user'
IAMUserAccessKey:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref IAMUser
IAMUserPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: !Sub '${AWS::StackName}-user-policy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub 'arn:aws:s3:::${AWS::StackName}-bucket'
- !Sub 'arn:aws:s3:::${AWS::StackName}-bucket/*'
- Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
- sqs:ChangeMessageVisibility
Resource: !GetAtt SQSQueue.Arn
- Effect: Allow
Action:
- ecs:*
Resource: '*'
- Effect: Allow
Action:
- iam:PassRole
Resource:
- !GetAtt ECSTaskExecutionRole.Arn
- !GetAtt ECSTaskRole.Arn
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:DeleteObject
Resource:
- !Sub 'arn:aws:s3:::${AWS::StackName}-bucket/*'
Users:
- !Ref IAMUser
ECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Sub '${AWS::StackName}-cluster'
ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub '${AWS::StackName}-task'
Cpu: '2048'
Memory: '4096'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: !Ref ECSTaskExecutionRole
TaskRoleArn: !Ref ECSTaskRole
ContainerDefinitions:
- Name: !Sub '${AWS::StackName}-container'
Image: !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${ECRRepository}:latest'
Essential: true
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Sub '/ecs/${AWS::StackName}-task'
awslogs-create-group: 'true'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: 'ecs'
RuntimePlatform:
CpuArchitecture: X86_64
OperatingSystemFamily: LINUX
ECSTaskExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy
ECSTaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ECRRepository:
Type: AWS::ECR::Repository
Properties:
RepositoryName: !Sub '${AWS::StackName}-repo'
CloudWatchLogsGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub '/ecs/${AWS::StackName}-task'
RetentionInDays: 30
Outputs:
S3BucketName:
Description: Name of the created S3 bucket
Value: !Ref S3Bucket
SQSQueueURL:
Description: URL of the created SQS queue
Value: !Ref SQSQueue
SQSQueueARN:
Description: ARN of the created SQS queue
Value: !GetAtt SQSQueue.Arn
IAMUserName:
Description: Name of the created IAM user
Value: !Ref IAMUser
IAMUserAccessKey:
Description: Access Key for the IAM user
Value: !Ref IAMUserAccessKey
IAMUserSecretKey:
Description: Secret Key for the IAM user
Value: !GetAtt IAMUserAccessKey.SecretAccessKey
ECSClusterARN:
Description: ARN of the ECS cluster
Value: !GetAtt ECSCluster.Arn
ECSTaskDefinitionArn:
Description: ARN of the ECS task definition
Value: !Ref ECSTaskDefinition
ECRRepositoryUri:
Description: URI of the ECR repository
Value: !GetAtt ECRRepository.RepositoryUri