-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathserverless.yml
134 lines (125 loc) · 3.93 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
custom:
profile: umihico # aws account configured in ~/.aws/credentials
service: portfoliohub # project name
certificateName: umihi.co # certificated domain in AWS Certificate Manager
domainName-prod: portfoliohub.umihi.co # domain name
domainName-stg: stg-${self:custom.domainName-prod}
cloudfrontDomainName-prod: portfoliohub-content.umihi.co
cloudfrontDomainName-stg: stg-${self:custom.cloudfrontDomainName-prod}
pythonRequirements:
dockerizePip: true
customDomain:
domainName: ${self:custom.domainName-${opt:stage, self:provider.stage}}
basePath: ""
stage: ${opt:stage, self:provider.stage}
certificateName: ${self:custom.certificateName}
createRoute53Record: true
scheduleInterval:
prod: 10
stg: 1440
service:
name: ${self:custom.service}
provider:
name: aws
region: ap-northeast-1
runtime: python3.7
stage: stg
profile: ${self:custom.profile}
environment: ${file(./${opt:stage, self:provider.stage}.yml)}
apiGateway:
binaryMediaTypes:
- "*/*"
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:getObject"
- "s3:putObject"
Resource: "arn:aws:s3:::*/*"
plugins:
- ./vendor/bref/bref
- serverless-domain-manager
- serverless-python-requirements
functions:
laravel:
handler: public/index.php
runtime: provided
timeout: 28
layers:
- ${bref:layer.php-73-fpm}
events:
- http: "ANY /"
- http: "ANY /{proxy+}"
scraping:
handler: main.main
timeout: 120
memorySize: 512
runtime: python3.7
layers:
- arn:aws:lambda:ap-northeast-1:${env:AWS_ACCOUNT_ID}:layer:pyyaml:1
- arn:aws:lambda:ap-northeast-1:${env:AWS_ACCOUNT_ID}:layer:requests:2
- arn:aws:lambda:ap-northeast-1:${env:AWS_ACCOUNT_ID}:layer:selenium:7
- arn:aws:lambda:ap-northeast-1:${env:AWS_ACCOUNT_ID}:layer:mysql-connector-python:1
events:
- schedule: rate(${self:custom.scheduleInterval.${opt:stage, self:provider.stage}} minutes)
package:
exclude:
- node_modules/**
- .git/**
resources:
Resources:
ResourceBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.cloudfrontDomainName-${opt:stage, self:provider.stage}}
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: 404.html
DeletionPolicy: Retain
ResourceCloudfront:
Type: AWS::CloudFront::Distribution
DependsOn:
- ResourceBucket
Properties:
DistributionConfig:
Origins:
- DomainName: ${self:custom.cloudfrontDomainName-${opt:stage, self:provider.stage}}.s3-website-ap-northeast-1.amazonaws.com
Id: S3Origin
CustomOriginConfig:
HTTPPort: "80"
HTTPSPort: "443"
OriginProtocolPolicy: http-only
Enabled: true
HttpVersion: "http2"
DefaultRootObject: index.html
Aliases:
- ${self:custom.cloudfrontDomainName-${opt:stage, self:provider.stage}}
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
Compress: true
TargetOriginId: S3Origin
ForwardedValues:
QueryString: true
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_All
ViewerCertificate:
AcmCertificateArn: ${ssm:usacmarn}
SslSupportMethod: sni-only
ResourceDNSName:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: umihi.co.
RecordSets:
- Name: ${self:custom.cloudfrontDomainName-${opt:stage, self:provider.stage}}.
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName:
Fn::GetAtt: [ResourceCloudfront, DomainName]
Outputs:
ResourceCloudfrontDistributionId:
Value:
Ref: ResourceCloudfront