-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.js
executable file
·102 lines (93 loc) · 2.36 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
const config = require('config');
const tables = require('./src/table');
const env = config.util.getEnv('NODE_ENV');
const stage = ({
development: 'dev',
test: 'test',
staging: 'staging',
production: 'prod'
})[env];
const plugins = stage !== 'test'
? []
: ['serverless-dynamodb-local', 'serverless-offline'];
module.exports = {
service: 'serverless-rest-api',
provider: {
name: 'aws',
runtime: 'nodejs10.x',
role: `arn:aws:iam::${config.aws.accountId}:role/${config.aws.role}`,
iamRoleStatements: [
...Object.keys(config.sqs).map(name => ({
Effect: 'Allow',
Action: ['sqs:SendMessage', 'sqs:GetQueueUrl', 'sqs:ListQueues'],
Resource: `arn:aws:sqs:${config.aws.region}:${config.aws.accountId}:${config.sqs[name]}`
})),
...Object.keys(tables).map(name => ({
Effect: 'Allow',
Action: ['dynamodb:Query', 'dynamodb:Scan', 'dynamodb:GetItem', 'dynamodb:PutItem', 'dynamodb:UpdateItem', 'dynamodb:DeleteItem'],
Resource: `arn:aws:dynamodb:${config.aws.region}:*:table/${name}`
}))
],
stage,
environment: { NODE_ENV: env }
},
custom: {
'serverless-offline': { port: config.sls.offline.port },
dynamodb: {
stages: ['test'],
start: {
port: config.dynamodb.port,
inMemory: true,
migrate: true
}
}
},
functions: {
createPig: {
handler: 'src/handler/pig.create',
events: [{
http: { path: '/api/pigs', method: 'POST' }
}]
},
getPig: {
handler: 'src/handler/pig.get',
events: [{
http: { path: '/api/pigs/{id}', method: 'GET' }
}]
}
},
resources: {
Resources: {
...Object.keys(tables).reduce((obj, name) => (Object.assign(obj,
{
[name]: {
Type: 'AWS::DynamoDB::Table',
Properties: tables[name]
}
})), {}),
...Object.keys(config.sqs).reduce((obj, name) => (Object.assign(obj,
{
[name]: {
Type: 'AWS::SQS::Queue',
Properties: { QueueName: config.sqs[name] }
}
})), {})
}
},
plugins,
package: {
exclude: [
'.nyc_output/**',
'bin/**',
'coverage/**',
'test/**',
'.eslintignore',
'.eslintrc',
'.nycrc',
'README.md',
'test.js',
'tables/**',
'.dynamodb/**'
]
}
};