-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.ts
116 lines (113 loc) · 3.61 KB
/
serverless.ts
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
import type { AWS } from '@serverless/typescript';
import { config, poll } from './src/functions';
const serverlessConfiguration: AWS = {
service: '${file(./package.json):name}',
frameworkVersion: '2',
useDotenv: true,
plugins: [
'serverless-webpack',
'serverless-plugin-aws-alerts',
'serverless-domain-manager',
'serverless-offline',
],
provider: {
name: 'aws',
runtime: 'nodejs14.x',
region: '${env:AWS_REGION}' as AWS['provider']['region'],
logRetentionInDays: 30,
stage: '${opt:stage, env:ENV}', // you can override this via the CLI argument
apiGateway: {
minimumCompressionSize: 1024, // Enable gzip compression for responses > 1 KB
shouldStartNameWithService: true,
apiKeys: ['${self:service}-key-${self:provider.stage}'],
usagePlan: {
quota: { limit: 2000, period: 'MONTH' },
throttle: { burstLimit: 10, rateLimit: 5 },
},
},
environment: {
// Service wide environment variables
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
STAGE: '${self:provider.stage}',
AWS_SSM_PREFIX: '/${self:service}/${self:provider.stage}',
},
iamRoleStatements: [
{
Effect: 'Allow',
Action: ['ssm:GetParameter'],
Resource:
'arn:aws:ssm:${self:provider.region}:${env:AWS_ACCOUNT_ID}:parameter${self:provider.environment.AWS_SSM_PREFIX}/*',
},
{
Effect: 'Allow',
Action: ['kms:Decrypt'],
Resource:
'arn:aws:kms:${self:provider.region}:${env:AWS_ACCOUNT_ID}:key/CMK',
},
],
lambdaHashingVersion: '20201221',
},
custom: {
period: { development: 300, production: 60 },
enabled: { development: false, production: true },
webpack: { webpackConfig: './webpack.config.js', includeModules: true },
customDomain: {
basePath: 'lambda-poll-estate',
domainName: '${env:CUSTOM_DOMAIN}',
createRoute53Record: false,
},
alerts: {
topics: {
alarm: {
topic:
'arn:aws:sns:eu-central-1:009255630476:alert-Topic-N47IM5J07MP7',
},
},
definitions: {
functionThrottles: {
treatMissingData: 'notBreaching',
period: '${self:custom.period.${self:provider.stage}}',
},
functionErrors: {
treatMissingData: 'notBreaching',
period: '${self:custom.period.${self:provider.stage}}',
},
functionInvocations: {
threshold: 50,
treatMissingData: 'notBreaching',
period: '${self:custom.period.${self:provider.stage}}',
},
functionDuration: {
threshold: 20000,
treatMissingData: 'notBreaching',
period: '${self:custom.period.${self:provider.stage}}',
},
statusCodeErrors: {
metric: 'statusCodeErrors',
threshold: 0,
statistic: 'Sum',
period: '${self:custom.period.${self:provider.stage}}',
evaluationPeriods: 1,
comparisonOperator: 'GreaterThanThreshold',
pattern: '{$.statusCode != 200}',
treatMissingData: 'missing',
},
},
alarms: [
{
name: 'functionThrottles',
enabled: '${self:custom.enabled.${self:provider.stage}}',
},
{ name: 'functionErrors', enabled: true },
{ name: 'functionInvocations', enabled: true },
{
name: 'functionDuration',
enabled: '${self:custom.enabled.${self:provider.stage}}',
},
{ name: 'statusCodeErrors', enabled: true },
],
},
},
functions: { poll, config },
};
module.exports = serverlessConfiguration;