-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.js
153 lines (144 loc) · 5.58 KB
/
serverless.js
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
/* eslint-disable no-multi-spaces */ // 'cuz clarify paired structure
/* eslint-disable no-template-curly-in-string */ // 'cuz syntax of the serverless framework
/* eslint-disable @typescript-eslint/no-var-requires */ // 'cuz of the JavaScript file
/*
* Command line options
* --stage: Stage as a system landscape, default is 'dev' (Choice: [dev | prd], e.g. --stage dev)
* --region: Region to deploy, default is determined by the value of `stage` (e.g. --region ap-northeast-1)
* --bucket: Buckets to be used for deployment, or to specify when deploying to different accounts (e.g. --bucket my-deploys)
* --aws-profile: Optional, when specifying AWS Profile name (If `devops` exists in `~/.aws/credentials`, e.g. --aws-profile devops)
*/
const pkg = require('./package.json');
module.exports = {
service: pkg.name,
provider: {
name: 'aws',
stage: '${opt:stage, "dev"}',
region: '${opt:region, self:custom.stages.region.${self:provider.stage}}',
runtime: `nodejs${pkg.engines.node.replace('>=', '')}`,
apiName: '${self:service}${self:custom.stages.suffix.${self:provider.stage}}',
memorySize: 256,
timeout: 29,
logRetentionInDays: 7,
versionFunctions: false,
deploymentBucket: {
name: '${opt:bucket, "x-sls-artifacts-' + pkg.group + '-${self:provider.region}"}', /* eslint-disable-line prefer-template */ // 'cuz syntax of the serverless framework
maxPreviousDeploymentArtifacts: 1,
blockPublicAccess: true,
serverSideEncryption: 'AES256'
},
iamRoleStatements: [{
Effect: 'Allow',
Action: [
'dynamodb:GetItem',
'dynamodb:Query',
'dynamodb:PutItem',
'dynamodb:UpdateItem'
],
Resource: [
{ 'Fn::GetAtt': [ 'RoomsTable', 'Arn' ]},
{ 'Fn::Join': [ '/', [{ 'Fn::GetAtt': [ 'RoomsTable', 'Arn' ]}, 'index', 'roomId-index' ]]}
]
}],
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
}
},
plugins: [
'serverless-webpack',
'serverless-offline',
'serverless-dynamodb-ttl'
],
custom: {
webpack: { packager: 'yarn', webpackConfig: 'deploy/webpack.config.js', includeModules: { forceExclude: [ 'aws-sdk' ]}},
stages: {
region: { dev: 'ap-northeast-1', prd: '' },
suffix: { dev: '-dev', prd: '' }
},
names: {
'lambda-systems': '${self:service}-systems${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-post-rooms': '${self:service}-post-rooms${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-get-rooms': '${self:service}-get-rooms${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-get-rooms-roomId': '${self:service}-get-rooms-roomId${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-post-rooms-roomId': '${self:service}-post-rooms-roomId${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-get-rooms-match': '${self:service}-get-rooms-match${self:custom.stages.suffix.${self:provider.stage}}'
},
dynamodb: {
ttl: [
{
table: 'Rooms',
field: 'expiresAt'
}
]
}
},
functions: {
Systems: {
name: '${self:custom.names.lambda-systems}',
handler: 'src/aws-lambda-handler/systems.handle',
events: [{ http: { path: 'version', method: 'get', cors: true }}]
},
GetRooms: {
name: '${self:custom.names.lambda-get-rooms}',
handler: 'src/aws-lambda-handler/list-rooms.handle',
events: [{ http: { path: 'rooms', method: 'get', cors: true }}]
},
PostRooms: {
name: '${self:custom.names.lambda-post-rooms}',
handler: 'src/aws-lambda-handler/new-room.handle',
events: [{ http: { path: 'rooms', method: 'post', cors: true }}]
},
GetRoomsRoomId: {
name: '${self:custom.names.lambda-get-rooms-roomId}',
handler: 'src/aws-lambda-handler/get-room.handle',
events: [{ http: { path: 'rooms/{roomId}', method: 'get', cors: true }}]
},
PostRoomsRoomId: {
name: '${self:custom.names.lambda-post-rooms-roomId}',
handler: 'src/aws-lambda-handler/add-rapper.handle',
events: [{ http: { path: 'rooms/{roomId}', method: 'post', cors: true }}]
},
GetRoomsRoomIdMatch: {
name: '${self:custom.names.lambda-get-rooms-match}',
handler: 'src/aws-lambda-handler/list-match-rooms.handle',
events: [{ http: { path: 'rooms/match', method: 'get', cors: true }}]
}
},
resources: [{
Resources: {
RoomsTable: {
Type: 'AWS::DynamoDB::Table',
Properties: {
TableName: 'Rooms',
AttributeDefinitions: [
{ AttributeName: 'registeredDateYearMonth', AttributeType: 'S' },
{ AttributeName: 'registeredDateRoomId', AttributeType: 'S' },
{ AttributeName: 'roomId', AttributeType: 'S' }
],
KeySchema: [
{ AttributeName: 'registeredDateYearMonth', KeyType: 'HASH' },
{ AttributeName: 'registeredDateRoomId', KeyType: 'RANGE' }
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
GlobalSecondaryIndexes: [{
IndexName: 'roomId-index',
KeySchema: [
{ AttributeName: 'roomId', KeyType: 'HASH' },
{ AttributeName: 'registeredDateRoomId', KeyType: 'RANGE' }
],
Projection: {
ProjectionType: 'ALL'
},
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
}]
}
}
}
}]
};