-
Notifications
You must be signed in to change notification settings - Fork 17
/
serverless.yml
256 lines (237 loc) · 10 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# スタック名: ${env:ALIS_APP_ID}-laboratory
service: ${env:ALIS_APP_ID}
frameworkVersion: ">=1.47.0 <2.0.0"
custom:
bucket: ${env:ALIS_APP_ID}-alis-laboratory
provider:
name: aws
runtime: python3.9
stage: laboratory # CloudFrontとの連携の都合上、stageには固定値を指定している
region: ap-northeast-1
role: LaboLambdaRole
tracing:
apiGateway: true
lambda: true
logs:
restApi: true
environment:
# Labo
LABO_S3_BUCKET_NAME: ${env:ALIS_APP_ID}-${self:provider.stage}-s3-bucket
MAJORITY_JUDGEMENT_TABLE_NAME: "${env:ALIS_APP_ID}-${self:provider.stage}-MajorityJudgment"
QUADRATIC_VOTING_TABLE_NAME: "${env:ALIS_APP_ID}-${self:provider.stage}-QuadraticVoting"
# 既存システム
ARTICLE_INFO_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleInfoTableName}
ARTICLE_CONTENT_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleContentTableName}
ARTICLE_HISTORY_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleHistoryTableName}
ARTICLE_CONTENT_EDIT_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleContentEditTableName}
ARTICLE_EVALUATED_MANAGE_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleEvaluatedManageTableName}
ARTICLE_ALIS_TOKEN_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleAlisTokenTableName}
ARTICLE_LIKED_USER_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleLikedUserTableName}
ARTICLE_FRAUD_USER_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleFraudUserTableName}
ARTICLE_PV_USER_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticlePvUserTableName}
ARTICLE_SCORE_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmArticleScoreTableName}
USERS_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmUsersTableName}
BETA_USERS_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmBetaUsersTableName}
NOTIFICATION_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmNotificationTableName}
UNREAD_NOTIFICATION_MANAGER_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmUnreadNotificationManagerTableName}
COMMENT_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmCommentTableName}
COMMENT_LIKED_USER_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmCommentLikedUserTableName}
DELETED_COMMENT_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmDeletedCommentTableName}
USER_FRAUD_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmUserFraudTableName}
SCREENED_ARTICLE_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmScreenedArticleTableName}
TOKEN_DISTRIBUTION_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmTokenDistributionTableName}
USER_FIRST_EXPERIENCE_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmUserFirstExperienceTableName}
TOPIC_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmTopicTableName}
TAG_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmTagTableName}
TIP_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmTipTableName}
EXTERNAL_PROVIDER_USERS_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmExternalProviderUsersTableName}
DOMAIN: ${ssm:${env:ALIS_APP_ID}ssmAlisAppDomain}
PUBLIC_CHAIN_OPERATION_URL: ${ssm:${env:ALIS_APP_ID}ssmPublicChainOperationUrl}
PUBLIC_CHAIN_LICENSE_TOKEN_ADDRESS: "${ssm:${env:ALIS_APP_ID}ssmPublicChainLicenseTokenAddress}"
PRIVATE_CHAIN_AWS_ACCESS_KEY: ${ssm:${env:ALIS_APP_ID}ssmPrivateChainAwsAccessKey}
PRIVATE_CHAIN_AWS_SECRET_ACCESS_KEY: ${ssm:${env:ALIS_APP_ID}ssmPrivateChainAwsSecretAccessKey}
PRIVATE_CHAIN_EXECUTE_API_HOST: ${ssm:${env:ALIS_APP_ID}ssmPrivateChainExecuteApiHost}
BETA_MODE_FLAG: ${ssm:${env:ALIS_APP_ID}ssmBetaModeFlag}
DIST_S3_BUCKET_NAME: ${ssm:${env:ALIS_APP_ID}ssmDistS3BucketName}
ELASTIC_SEARCH_ENDPOINT: ${ssm:${env:ALIS_APP_ID}ssmElasticSearchEndpoint}
PAID_ARTICLES_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmPaidArticlesTableName}
PAID_STATUS_TABLE_NAME: ${ssm:${env:ALIS_APP_ID}ssmPaidStatusTableName}
# パッケージは packaging.sh で生成されたものを使用する
package:
individually: true
functions:
LaboNRandom:
description: "記事をランダムに表示"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_random.zip
events:
- http:
method: get
# CloudFrontによるキャッシュを利かさないものは /n/ 以下に配置する
path: /labo/n/random
MajorityJudgementIndex:
description: "MajorityJudgementの画面を表示する。既に登録済であれば登録済画面を表示する"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_majority_judgement_index.zip
events:
- http:
method: get
path: /labo/n/majority_judgement
authorizer:
name: cognitoUserPool
arn: ${ssm:${env:ALIS_APP_ID}ssmCognitoUserPoolArn}
MajorityJudgementCreate:
description: "MajorityJudgementの投票を行う"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_majority_judgement_create.zip
events:
- http:
method: post
path: /labo/n/majority_judgement
authorizer:
name: cognitoUserPool
arn: ${ssm:${env:ALIS_APP_ID}ssmCognitoUserPoolArn}
MajorityJudgementDeleteAll:
description: "MajorityJudgementのDBの内容クリアする"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_majority_judgement_delete_all.zip
QuadraticVotingIndex:
description: "QuadraticVotingの画面を表示する。既に登録済であれば登録済画面を表示する"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_quadratic_voting_index.zip
events:
- http:
method: get
path: /labo/n/quadratic_voting
authorizer:
name: cognitoUserPool
arn: ${ssm:${env:ALIS_APP_ID}ssmCognitoUserPoolArn}
QuadraticVotingCreate:
description: "QuadraticVotingの投票を行う"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_quadratic_voting_create.zip
events:
- http:
method: post
path: /labo/n/quadratic_voting
authorizer:
name: cognitoUserPool
arn: ${ssm:${env:ALIS_APP_ID}ssmCognitoUserPoolArn}
LicenseTokenFileUploadUrl:
description: "ライセンストークンに対応するファイルのアップロード用URLを取得する"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_license_token_file_upload_url.zip
events:
- http:
method: get
path: /labo/n/license_token/file_upload_url
authorizer:
name: cognitoUserPool
arn: ${ssm:${env:ALIS_APP_ID}ssmCognitoUserPoolArn}
LicenseTokenFileDownloadUrl:
description: "ライセンストークンに対応するファイルのダウンロード用URLを取得する"
handler: handler.lambda_handler
package:
artifact: ./deploy/labo_n_license_token_file_download_url.zip
events:
- http:
method: get
path: /labo/n/license_token/file_download_url
resources:
Resources:
# Laboは既存システムと疎結合にするためIAM Roleを分離する
# Outputsするためproviderではなくここに定義している
LaboLambdaRole:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: "${env:ALIS_APP_ID}-LaboLambdaRole"
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
Service:
- lambda.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess
- arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
- arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess
LaboLambdaRolePolicies:
Type: AWS::IAM::Policy
Properties:
PolicyName: "${env:ALIS_APP_ID}-LaboLambdaRolePolicies"
PolicyDocument:
Version: "2012-10-17"
Statement:
# LaboリソースからのDynamoDBの更新は、原則としてLaboリソース専用のDynamoDBテーブル以外は許可しない
- Effect: Allow
Action: dynamodb:*
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${env:ALIS_APP_ID}-${self:provider.stage}-*"
# LaboリソースからのS3の更新は、原則としてLaboリソース専用のS3以外は許可しない
- Effect: Allow
Action: s3:*
Resource:
- "arn:aws:s3:::${env:ALIS_APP_ID}-${self:provider.stage}-s3-bucket"
- "arn:aws:s3:::${env:ALIS_APP_ID}-${self:provider.stage}-s3-bucket/*"
Roles:
- Ref: LaboLambdaRole
# DynamoDB
MajorityJudgmentDB:
Type: AWS::DynamoDB::Table
DeletionPolicy: 'Retain'
Properties:
TableName: "${env:ALIS_APP_ID}-${self:provider.stage}-MajorityJudgment"
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
BillingMode: PAY_PER_REQUEST
QuadraticVotingDB:
Type: AWS::DynamoDB::Table
DeletionPolicy: 'Retain'
Properties:
TableName: "${env:ALIS_APP_ID}-${self:provider.stage}-QuadraticVoting"
AttributeDefinitions:
- AttributeName: user_id
AttributeType: S
KeySchema:
- AttributeName: user_id
KeyType: HASH
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
BillingMode: PAY_PER_REQUEST
# S3
S3BucketLabo:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
BucketName: ${env:ALIS_APP_ID}-${self:provider.stage}-s3-bucket
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- PUT
AllowedOrigins:
- "*"
AllowedHeaders:
- "*"
Outputs:
# Elasticsearchで指定する必要があるためExport
LaboLambdaRole:
Value:
Fn::GetAtt: LaboLambdaRole.Arn
Export:
Name: "${env:ALIS_APP_ID}-LaboLambdaRole"