-
Notifications
You must be signed in to change notification settings - Fork 4
/
stack.yml
202 lines (189 loc) · 5.13 KB
/
stack.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
---
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Video S3 Import
Parameters:
ORG:
Type: 'String'
Description: 'Your ARC organization ID'
ENV:
Type: 'String'
Description: 'sandbox | prod'
AllowedValues: ['sandbox', 'prod']
ArcToken:
Type: 'String'
Description: 'Your ARC API token'
VideoExpirationInDays:
Type: 'Number'
Description: 'How many days until the video is deleted from the bucket?'
SshPublicKey:
Type: 'String'
Description: 'Your SFTP SSH public key'
Conditions:
UseSFTP: !Not [!Equals [!Ref SshPublicKey, '']]
#
# CloudFormation resources
#
Resources:
#
# Role that our Lambda will assume to provide access to other AWS resources
#
IamRoleLambdaExecution:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: '/'
#
# Create a Policy and attach it to our Lambda Role.
#
IamPolicyLambdaExecution:
Type: AWS::IAM::Policy
Properties:
PolicyName: IamPolicyLambdaExecution
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub 'arn:aws:s3:::arc-video-center-ingest-${ORG}-${ENV}'
- !Sub 'arn:aws:s3:::arc-video-center-ingest-${ORG}-${ENV}/*'
Roles:
- Ref: IamRoleLambdaExecution
#
# Lambda function
#
ArcVideoCenterIngestLambda:
Type: AWS::Serverless::Function
DependsOn: IamPolicyLambdaExecution
Properties:
Role: !GetAtt IamRoleLambdaExecution.Arn
Description: 'Imports videos into the video CMS from a dedicated folder structure'
MemorySize: 128
Timeout: 10
ReservedConcurrentExecutions: 10
Runtime: nodejs10.x
CodeUri: ./
Handler: index.handler
Environment:
Variables:
ORG: !Ref ORG
ENV: !Ref ENV
ArcToken: !Ref ArcToken
VideoExpirationInDays: !Ref VideoExpirationInDays
Tags:
App: ARC Video Center Ingest
#
# Lambda Execution Permission
#
ArcVideoCenterIngestLambdaInvokePermission:
Type: AWS::Lambda::Permission
DependsOn: ArcVideoCenterIngestLambda
Properties:
FunctionName: !Ref ArcVideoCenterIngestLambda
Principal: s3.amazonaws.com
Action: lambda:InvokeFunction
SourceAccount:
Ref: AWS::AccountId
#
# S3 Bucket with Lambda trigger
#
ArcVideoCenterIngestBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub 'arc-video-center-ingest-${ORG}-${ENV}'
AccessControl: 'Private'
NotificationConfiguration:
LambdaConfigurations:
- Event: 's3:ObjectCreated:*'
Function: !GetAtt ArcVideoCenterIngestLambda.Arn
LifecycleConfiguration:
Rules:
- Id: 'ExpireAfter'
Status: Enabled
ExpirationInDays: !Ref VideoExpirationInDays
TagFilters:
- Key: ArcExpire
Value: 'True'
#
# SFTP
#
IamRoleSFTPExecution:
Type: AWS::IAM::Role
Condition: UseSFTP
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- transfer.amazonaws.com
Action:
- sts:AssumeRole
Path: '/'
IamPolicySFTPExecution:
Type: AWS::IAM::Policy
Condition: UseSFTP
Properties:
PolicyName: IamPolicySFTPExecution
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub 'arn:aws:s3:::arc-video-center-ingest-${ORG}-${ENV}'
- !Sub 'arn:aws:s3:::arc-video-center-ingest-${ORG}-${ENV}/*'
Roles:
- Ref: IamRoleSFTPExecution
SFTP:
Type: AWS::Transfer::Server
Condition: UseSFTP
Properties:
EndpointType: PUBLIC
IdentityProviderType: SERVICE_MANAGED
FTPUser:
Type : AWS::Transfer::User
Condition: UseSFTP
Properties :
HomeDirectory: !Sub '/${ArcVideoCenterIngestBucket}'
HomeDirectoryType: PATH
Role: !GetAtt IamRoleSFTPExecution.Arn
ServerId: !GetAtt SFTP.ServerId
SshPublicKeys:
- !Sub 'ssh-rsa ${SshPublicKey}'
UserName: !Sub 'arc-vc-ingest-${ENV}'
#
# Outputs
#
Outputs:
ArcVideoCenterIngestLambda:
Description: Lambda Function Name
Value: !Ref ArcVideoCenterIngestLambda
ArcVideoCenterIngestLambdaArn:
Description: Lambda Function ARN
Value: !GetAtt ArcVideoCenterIngestLambda.Arn
ArcVideoCenterIngestBucket:
Description: S3 Bucket
Value: !Ref ArcVideoCenterIngestBucket
SFTP:
Condition: UseSFTP
Description: SFTP
Value: !Ref SFTP