This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 242
/
image-resize.yaml
72 lines (65 loc) · 1.89 KB
/
image-resize.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
Api:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: ./deploy/api.yaml
StageName: prod
Variables:
LambdaFunctionName: !Ref ResizeFunction
ImageBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
RoutingRules:
- RedirectRule:
HttpRedirectCode: 307
HostName: !Sub ${Api}.execute-api.${AWS::Region}.amazonaws.com
Protocol: https
ReplaceKeyPrefixWith: prod?key=
RoutingRuleCondition:
HttpErrorCodeReturnedEquals: 404
ResizeFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist/function.zip
Handler: index.handler
Runtime: nodejs6.10
MemorySize: 1536
Timeout: 60
Environment:
Variables:
BUCKET: !Ref ImageBucket
URL: !GetAtt ImageBucket.WebsiteURL
Policies:
Statement:
- Resource: !Sub arn:aws:s3:::${ImageBucket}/*
Effect: Allow
Action:
- s3:PutObject
ResizeFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref ResizeFunction
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${Api}/*
ImageBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref ImageBucket
PolicyDocument:
Statement:
- Action: s3:GetObject
Effect: Allow
Principal: "*"
Resource: !Sub arn:aws:s3:::${ImageBucket}/*
Outputs:
BucketWebsiteUrl:
Value: !GetAtt ImageBucket.WebsiteURL
Bucket:
Value: !Ref ImageBucket