-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
171 lines (165 loc) · 5.32 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
service: web-poc
custom:
dev:
COOKIE_SECRET: ${ssm:web_cookie_secret_dev}
SESSION_TABLE_MIN_READ_TP: 1
SESSION_TABLE_MAX_READ_TP: 10
SESSION_TABLE_MIN_WRITE_TP: 1
SESSION_TABLE_MAX_WRITE_TP: 10
GOOGLE_TAG_MANAGER_ID: ''
AMPLITUDE_KEY: ${ssm:web_amplitude_dev_key}
uat:
prod:
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: eu-west-2
versionFunctions: false
environment:
NODE_PORT: 80
DYNAMODB_LIVE: true
STORYBOOK: true
LOG_LEVEL: info
STAGE: ${opt:stage, self:provider.stage}
DYNAMODB_SESSION_TABLE: ${opt:stage, self:provider.stage}-${self:service}-web-sessions-sse
COOKIE_SECRET: ${self:custom.${opt:stage, self:provider.stage}.COOKIE_SECRET}
GOOGLE_TAG_MANAGER_ID: ${self:custom.${opt:stage, self:provider.stage}.GOOGLE_TAG_MANAGER_ID}
AMPLITUDE_KEY: ${self:custom.${opt:stage, self:provider.stage}.AMPLITUDE_KEY}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:GetItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_SESSION_TABLE}"
package:
excludeDevDependencies: false
exclude:
- '**/*'
include:
- node_modules/**
- dist/**
- config/**
- .env
functions:
app:
handler: dist/server/lambda-index.handler
timeout: 30
reservedConcurrency: 100
events:
- http: 'ANY /'
- http: 'ANY {proxy+}'
resources:
Resources:
TokenTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: ${self:provider.environment.DYNAMODB_SESSION_TABLE}
SSESpecification:
SSEEnabled: true
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
KeySchema:
- AttributeName: sessionId
KeyType: HASH
AttributeDefinitions:
- AttributeName: sessionId
AttributeType: S
TimeToLiveSpecification:
Enabled: true
AttributeName: expire
GatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseType: DEFAULT_5XX
ResponseTemplates:
text/html: ${file(./dist/server/error-page.js):html}
RestApiId:
Ref: 'ApiGatewayRestApi'
WriteCapacityScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: ${self:custom.${opt:stage, self:provider.stage}.SESSION_TABLE_MAX_WRITE_TP}
MinCapacity: ${self:custom.${opt:stage, self:provider.stage}.SESSION_TABLE_MIN_WRITE_TP}
ResourceId:
Fn::Join:
- /
- - table
- Ref: "TokenTable"
RoleARN:
Fn::GetAtt: "ScalingRole.Arn"
ScalableDimension: dynamodb:table:WriteCapacityUnits
ServiceNamespace: dynamodb
ReadCapacityScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: ${self:custom.${opt:stage, self:provider.stage}.SESSION_TABLE_MAX_READ_TP}
MinCapacity: ${self:custom.${opt:stage, self:provider.stage}.SESSION_TABLE_MIN_READ_TP}
ResourceId:
Fn::Join:
- /
- - table
- Ref: "TokenTable"
RoleARN:
Fn::GetAtt: "ScalingRole.Arn"
ScalableDimension: dynamodb:table:ReadCapacityUnits
ServiceNamespace: dynamodb
ScalingRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- application-autoscaling.amazonaws.com
Action:
- "sts:AssumeRole"
Path: "/"
Policies:
-
PolicyName: "root"
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "dynamodb:DescribeTable"
- "dynamodb:UpdateTable"
- "cloudwatch:PutMetricAlarm"
- "cloudwatch:DescribeAlarms"
- "cloudwatch:GetMetricStatistics"
- "cloudwatch:SetAlarmState"
- "cloudwatch:DeleteAlarms"
Resource: "*"
WriteScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: WriteAutoScalingPolicy
PolicyType: TargetTrackingScaling
ScalingTargetId:
Ref: "WriteCapacityScalableTarget"
TargetTrackingScalingPolicyConfiguration:
TargetValue: 50.0
ScaleInCooldown: 60
ScaleOutCooldown: 60
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBWriteCapacityUtilization
ReadScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: ReadAutoScalingPolicy
PolicyType: TargetTrackingScaling
ScalingTargetId:
Ref: "ReadCapacityScalableTarget"
TargetTrackingScalingPolicyConfiguration:
TargetValue: 50.0
ScaleInCooldown: 60
ScaleOutCooldown: 60
PredefinedMetricSpecification:
PredefinedMetricType: DynamoDBReadCapacityUtilization