-
Notifications
You must be signed in to change notification settings - Fork 1
/
sam-template.yaml
101 lines (101 loc) · 2.93 KB
/
sam-template.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'Generates a thumbnail for videos uploaded to a S3 bucket.'
Resources:
InputBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Ref InputBucketName
NotificationConfiguration:
TopicConfigurations:
- Event: 's3:ObjectCreated:*'
Topic: !Ref BucketCreatedTopic
DependsOn: ['BucketCreatedTopicPolicy']
ThumbnailBucket:
Type: 'AWS::S3::Bucket'
Properties: {}
Topic:
Type: 'AWS::SNS::Topic'
Properties: {}
BucketCreatedTopic:
Type: 'AWS::SNS::Topic'
Properties: {}
BucketCreatedTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
Topics:
- !Ref BucketCreatedTopic
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: s3.amazonaws.com
Action: ['SNS:Publish']
Resource: '*'
Condition:
ArnLike:
'aws:SourceArn': !Join ['', ['arn:aws:s3:::', !Ref InputBucketName]]
FfmpegLambdaLayer:
Type: 'AWS::Serverless::Application'
Properties:
Location:
ApplicationId: >-
arn:aws:serverlessrepo:us-east-1:145266761615:applications/ffmpeg-lambda-layer
SemanticVersion: 1.0.0
ThumbnailFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: generateThumbnail.handler
Runtime: nodejs12.x
CodeUri: src
MemorySize: 512
Timeout: 60
Policies:
- AWSLambdaExecute
- SNSPublishMessagePolicy:
TopicName: !GetAtt Topic.TopicName
Environment:
Variables:
THUMBNAIL_BUCKET: !Ref ThumbnailBucket
SNS_TOPIC: !Ref Topic
DEBUG: !Ref DebugLevel
MARKS: !Ref Marks
Layers:
- !GetAtt FfmpegLambdaLayer.Outputs.LayerVersion
Events:
SNS:
Type: SNS
Properties:
Topic: !Ref BucketCreatedTopic
Parameters:
DebugLevel:
Type: String
Default: ""
Description: "The DEBUG environment variable for the Lambda. Set to 'cloudformation-video-thumbnail' to enable debug."
Marks:
Type: String
Default: '0.01,0.25,0.5,0.75,0.99'
Description: "A comma-separated list of the points at which to take thumbnail screenshots."
InputBucketName:
Type: String
Description: "The name of the video input bucket."
Outputs:
InputBucket:
Description: S3 Input Bucket
Value: !Ref InputBucket
InputBucketArn:
Description: S3 Input Bucket ARN
Value: !GetAtt InputBucket.Arn
ThumbnailBucket:
Description: Thumbnail Bucket
Value: !Ref ThumbnailBucket
ThumbnailBucketArn:
Description: Thumbnail Bucket ARN
Value: !GetAtt ThumbnailBucket.Arn
Topic:
Description: SNS Notification Topic
Value: !Ref Topic
S3Topic:
Description: S3 Object Created SNS Topic
Value: !Ref BucketCreatedTopic