forked from Arahabica/line-mini-app-hands-on
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
198 lines (197 loc) · 5.99 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
service: your-name-line-member-card
frameworkVersion: '3'
custom:
app:
PUBLIC_BUCKET: ${self:custom.stack}
DEPLOYMENT_BUCKET: ${self:custom.stack}-deployment
S3_WEB_DOMAIN: ${self:custom.stack}.s3.${self:custom.region}.amazonaws.com
LINE_CHANNEL_ID: ${ssm:/${self:custom.stage}/${self:service}/LINE_CHANNEL_ID, ''}
LIFF_ID: ${ssm:/${self:custom.stage}/${self:service}/LIFF_ID, ''}
USER_TABLE: ${self:custom.stack}-user
VISIT_TABLE: ${self:custom.stack}-visit
region: ${opt:region, self:provider.region}
stage: ${opt:stage, self:provider.stage}
stack: ${self:service}-${self:custom.stage}
s3Sync:
- bucketName: ${self:custom.app.PUBLIC_BUCKET}
localDir: frontend/dist/
serverless-layers:
dependenciesPath: ./backend/package.json
plugins:
- serverless-s3-sync
- serverless-deployment-bucket
- serverless-layers
provider:
name: aws
runtime: nodejs16.x
region: ap-northeast-1
stage: dev
environment:
LINE_CHANNEL_ID: ${self:custom.app.LINE_CHANNEL_ID}
USER_TABLE: ${self:custom.app.USER_TABLE}
VISIT_TABLE: ${self:custom.app.VISIT_TABLE}
TZ: Asia/Tokyo
deploymentBucket:
name: ${self:custom.app.DEPLOYMENT_BUCKET}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- "arn:aws:dynamodb:${self:provider.region}:*:table/${self:custom.app.USER_TABLE}"
- "arn:aws:dynamodb:${self:provider.region}:*:table/${self:custom.app.VISIT_TABLE}"
package:
exclude:
- backend/node_modules/**
- backend/yarn.lock
- frontend/**
functions:
backend:
handler: backend/lambda.handler
events:
- http:
path: /
method: ANY
- http:
path: '{proxy+}'
method: ANY
resources:
Resources:
S3Storage:
Type: 'AWS::S3::Bucket'
Properties:
#AccessControl: PublicRead
BucketName: '${self:custom.app.PUBLIC_BUCKET}'
WebsiteConfiguration:
IndexDocument: index.html
OwnershipControls:
Rules:
- ObjectOwnership: ObjectWriter
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
StaticSiteS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: S3Storage
PolicyDocument:
Statement:
- Sid: PublicReadGetObject
Effect: Allow
Principal: "*"
Action:
- s3:GetObject
Resource:
Fn::Join: ["", ["arn:aws:s3:::",{"Ref": "S3Storage"},"/*"]]
StaticContentsCloudFront:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Enabled: true
Comment: "Delivery static contents"
PriceClass: PriceClass_200
DefaultRootObject: index.html
Origins:
- Id: ApiOrigin
DomainName:
Fn::Join: ["", [{"Ref": "ApiGatewayRestApi"},".execute-api.${self:custom.region}.amazonaws.com"]]
OriginPath: "/${self:custom.stage}"
CustomOriginConfig:
OriginProtocolPolicy: match-viewer
- Id: S3Origin
DomainName: ${self:custom.app.S3_WEB_DOMAIN}
CustomOriginConfig:
OriginProtocolPolicy: match-viewer
DefaultCacheBehavior:
AllowedMethods:
- HEAD
- GET
CachedMethods:
- HEAD
- GET
Compress: true
DefaultTTL: 0
MaxTTL: 0
MinTTL: 0
ForwardedValues:
QueryString: true
SmoothStreaming: false
TargetOriginId: S3Origin
ViewerProtocolPolicy: https-only
CacheBehaviors:
- TargetOriginId: ApiOrigin
PathPattern: "/api/*"
AllowedMethods:
- HEAD
- GET
- POST
- PUT
- DELETE
- OPTIONS
- PATCH
CachedMethods:
- HEAD
- GET
Compress: true
DefaultTTL: 0
MaxTTL: 0
MinTTL: 0
ForwardedValues:
QueryString: true
ViewerProtocolPolicy: https-only
CustomErrorResponses:
- ErrorCachingMinTTL: 0
ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /
StaticCloudFrontOriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment:
Ref: AWS::StackName
UserTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.app.USER_TABLE}
VisitTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: visitedAt
AttributeType: N
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: visitedAt
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.app.VISIT_TABLE}
Outputs:
StaticContentsCloudFrontUrl:
Value:
Fn::Join: ["", ["https://", {"Fn::GetAtt": ["StaticContentsCloudFront" , "DomainName"]}]]