-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
73 lines (68 loc) · 2.65 KB
/
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
S3 Triggers Demo
Sample SAM Template for REPS&Co Demo -- S3 Triggers
Parameters:
BucketNamePrefix:
Type: String
Default: reps-demo-triggers-bucket
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
SourceBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${BucketNamePrefix}-source-bucket"
DestBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "${BucketNamePrefix}-dest-bucket"
S3TriggersFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: s3_triggers/
Handler: app.lambda_handler
Runtime: python3.7
Policies:
- S3ReadPolicy:
BucketName: !Sub "${BucketNamePrefix}-source-bucket"
- S3CrudPolicy:
BucketName: !Sub "${BucketNamePrefix}-dest-bucket"
Environment:
Variables:
DestBucket: !Sub "${BucketNamePrefix}-dest-bucket"
Events:
ImageUpload:
Type: S3
Properties:
Bucket: !Ref SourceBucket
Events: s3:ObjectCreated:Put
# https://github.com/awslabs/serverless-application-model/issues/300
# had to add this resource, because without it, the Event Source wasn't displaying in Lambda Console
LambdaInvokePermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt S3TriggersFunction.Arn
Action: 'lambda:InvokeFunction'
Principal: 's3.amazonaws.com'
SourceAccount: !Sub ${AWS::AccountId}
SourceArn: !GetAtt SourceBucket.Arn
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
SourceBucket:
Description: "S3 Bucket name that will trigger a Lambda function upon new objects insertion"
Value: !Ref SourceBucket
DestBucket:
Description: "S3 Bucket name that will store the modified versions of the images from the source bucket"
Value: !Ref DestBucket
S3TriggersFunction:
Description: "S3 Triggers Lambda Function ARN"
Value: !GetAtt S3TriggersFunction.Arn
S3TriggersFunctionIamRole:
Description: "Implicit IAM Role created for S3 Triggers function"
Value: !GetAtt S3TriggersFunctionRole.Arn