-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
114 lines (104 loc) · 2.67 KB
/
template.yaml
File metadata and controls
114 lines (104 loc) · 2.67 KB
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Parameters:
InputBucketName:
Type: String
OutputBucketName:
Type: String
InputPrefix:
Type: String
Default: ''
InputSuffix:
Type: String
Default: pdf
OutputPrefix:
Type: String
Default: ''
OutputType:
Type: String
Default: pdf
AllowedValues:
- pdf
- png
Resources:
InputBucket:
Type: AWS::S3::Bucket
DependsOn: LambdaPermission
Properties:
BucketName: !Ref InputBucketName
NotificationConfiguration:
LambdaConfigurations:
- Event: 's3:ObjectCreated:*'
Function: !GetAtt LambdaFunction.Arn
Filter:
S3Key:
Rules:
-
Name: suffix
Value: !Ref InputSuffix
-
Name: prefix
Value: !Ref InputPrefix
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref LambdaFunction
Principal: s3.amazonaws.com
SourceAccount: !Ref "AWS::AccountId"
SourceArn: !Sub "arn:aws:s3:::${InputBucketName}"
LambdaPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: Lambda
Roles:
- !Ref LambdaRole
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
-
Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "arn:aws:s3:::${InputBucketName}/${InputPrefix}*${InputSuffix}"
-
Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
Resource: !Sub "arn:aws:s3:::${OutputBucketName}/${OutputPrefix}*"
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs22.x
CodeUri: ./lambda
Role: !GetAtt LambdaRole.Arn
Timeout: 300
MemorySize: 512
Environment:
Variables:
PREFIX: !Ref OutputPrefix
TYPE: !Ref OutputType
DESTINATION: !Ref OutputBucketName