-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.js
117 lines (109 loc) · 4.17 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
/* 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: [ 's3:PutObject' ],
Resource: 'arn:aws:s3:::${self:custom.names.s3-images}/*'
}],
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1,
STAGE: '${self:provider.stage}',
S3_IMAGES_REGION: '${self:provider.region}',
S3_IMAGES_BUCKET: '${self:custom.names.s3-images}',
SLACK_TOKENS: '${env:SLACK_TOKENS}',
YOLP_APP_ID: '${env:YOLP_APP_ID}',
NOTE: '${env:NOTE}'
}
},
plugins: [
'serverless-webpack',
'serverless-offline'
],
custom: {
webpack: { packager: 'yarn', webpackConfig: 'deploy/webpack.config.js', includeModules: { forceExclude: [ 'aws-sdk' ]}},
stages: {
region: { dev: 'ap-northeast-1', qas: 'ap-northeast-1', prd: 'ap-northeast-1' },
suffix: { dev: '-dev', qas: '-qas', prd: '' }
},
names: {
'lambda-systems': '${self:service}-systems${self:custom.stages.suffix.${self:provider.stage}}',
'lambda-command': '${self:service}-command${self:custom.stages.suffix.${self:provider.stage}}',
's3-images': '${self:service}-images${self:custom.stages.suffix.${self:provider.stage}}'
}
},
functions: {
Systems: {
name: '${self:custom.names.lambda-systems}',
handler: 'src/aws-lambda-handler/systems.handle',
events: [{ http: { path: 'version', method: 'get', cors: true }}]
},
Command: {
name: '${self:custom.names.lambda-command}',
handler: 'src/aws-lambda-handler/sora-kagami-command.handler',
events: [{ http: { path: 'sora-kagami', method: 'post', cors: true, async: true }}]
}
},
resources: [{
Resources: {
ImagesBucket: {
Type: 'AWS::S3::Bucket',
Properties: {
BucketName: '${self:custom.names.s3-images}',
BucketEncryption: { ServerSideEncryptionConfiguration: [{ ServerSideEncryptionByDefault: { SSEAlgorithm: 'AES256' }}]},
AccessControl: 'Private',
WebsiteConfiguration: {
IndexDocument: 'index.html'
},
LifecycleConfiguration: {
Rules: [{
Id: 'expiration',
Status: 'Enabled',
ExpirationInDays: 3
}]
}
}
},
ImagesBucketPolicy: {
Type: 'AWS::S3::BucketPolicy',
Properties: {
Bucket: { Ref: 'ImagesBucket' },
PolicyDocument: {
Statement: {
Effect: 'Allow',
Action: [ 's3:GetObject' ],
Resource: 'arn:aws:s3:::${self:custom.names.s3-images}/*',
Principal: '*'
}
}
}
}
}
}]
};