This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathserverless.yml
108 lines (96 loc) · 2.84 KB
/
serverless.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
service: lambda-screenshots
custom:
# change this, so it's unique for your setup
bucket_name: ${opt:stage,self:provider.stage}-${env:USER}-screenshots
stageVariables:
bucketName: ${self:custom.bucket_name}
endpoint: {"Fn::Join": ["", ["https://", { "Fn::GetAtt": "CloudFrontEndpoint.DomainName" }, "/"]]}
# timeout for phantomjs
screenshotTimeout: 3000
provider:
name: aws
runtime: nodejs4.3
stage: dev
region: us-east-1
# We need to lockdown the apigateway, so we can control who can use the api
apiKeys:
- app-api-key
# We need to give the lambda functions access to list and write to our bucket, it needs:
# - to be able to 'list' the bucket
# - to be able to upload a file (PutObject)
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:ListBucket"
- "s3:Put*"
- "s3:GetObject"
Resource:
- "arn:aws:s3:::${self:custom.bucket_name}"
- "arn:aws:s3:::${self:custom.bucket_name}/*"
functions:
takeScreenshot:
handler: handler.take_screenshot
timeout: 15
events:
- http:
path: screenshots
method: post
# Marking the function as private will require an api-key
private: true
# The url parameter is mandatory
request:
parameters:
# headers:
# foo: false
# bar: true
querystrings:
url: true
# paths:
# bar: false
listScreenshots:
handler: handler.list_screenshots
timeout: 15
events:
- http:
path: screenshots
method: get
private: true
request:
parameters:
querystrings:
url: true
createThumbnails:
handler: handler.create_thumbnails
events:
- s3:
bucket: ${self:custom.bucket_name}
event: s3:ObjectCreated:*
resources:
Outputs:
ScreenshotBucket:
Description: "Screenshot bucket name"
Value: ${self:custom.bucket_name}
CloudFrontUrl:
Description: "CloudFront url"
Value: {"Fn::GetAtt": "CloudFrontEndpoint.DomainName"}
Resources:
# Create an endpoint for the S3 bucket in CloudFront
CloudFrontEndpoint:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Enabled: True
DefaultCacheBehavior:
TargetOriginId: ScreenshotBucketOrigin
ViewerProtocolPolicy: redirect-to-https
ForwardedValues:
QueryString: True
Origins:
-
Id: ScreenshotBucketOrigin
DomainName: ${self:custom.bucket_name}.s3.amazonaws.com
CustomOriginConfig:
OriginProtocolPolicy: http-only
plugins:
- serverless-plugin-stage-variables
- serverless-plugin-stack-outputs