-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverless.yml
248 lines (243 loc) · 7.56 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
service: lambda-api-demo
plugins:
- serverless-offline-ssm
- serverless-offline
- serverless-pseudo-parameters
- serverless-dynamodb-local
custom:
dynamodb:
stages:
- local
- dev
start:
port: 8000
inMemory: true
heapInitial: 200m
heapMax: 1g
migrate: false
seed: false
convertEmptyValues: true
noStart: true
sharedDb: true
seed:
DemoTable:
sources:
- table: DemoDynamodbTable-${opt:stage}
sources: [./src/data/fakeUsers.json]
serverless-offline-ssm:
stages:
-
local
ssm:
'/demo/local/rds/demo-db-endpoint': 'localhost'
'/demo/local/rds/demo-db-name': 'test'
'/demo/local/rds/demo-db-username': 'notadmin'
'/demo/local/rds/demo-db-password': 'notpassword'
'/demo/local/vpc/vpc_endpoint_sns_sg': 'vpc_endpoint_sns_s'
'/demo/local/vpc/private_subnet_a': 'private_subnet_a'
'/demo/local/vpc/private_subnet_b': 'private_subnet_b'
'/demo/local/lambda_security_group': 'lambda_security_group'
'/demo/local/slack_endpoint': 'http://localhost:3001/local_webhook'
provider:
name: aws
runtime: nodejs12.x
region: us-east-2
timeout: 06
tracing:
lambda: true
apiGateway: true
environment:
NODE_ENV: ${opt:stage}
functions:
DemoLambda:
role: DemoLambdaRole
handler: src/functions/endpoints/index.handler
vpc:
securityGroupIds:
- ${ssm:/demo/${opt:stage}/lambda_security_group}
- ${ssm:/demo/${opt:stage}/vpc/vpc_endpoint_sns_sg}
subnetIds:
- ${ssm:/demo/${opt:stage}/vpc/private_subnet_a}
- ${ssm:/demo/${opt:stage}/vpc/private_subnet_b}
environment:
TopicArn: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:demo-sns-topic-${opt:stage}
DB_HOST: ${ssm:/demo/${opt:stage}/rds/demo-db-endpoint}
DB_PORT: 5432
DB_NAME: ${ssm:/demo/${opt:stage}/rds/demo-db-name}
DB_USER: ${ssm:/demo/${opt:stage}/rds/demo-db-username~true}
DB_PASS: ${ssm:/demo/${opt:stage}/rds/demo-db-password~true}
events:
- http:
path: /send_data
method: GET
- http:
path: /send_data_rds
method: GET
- http:
path: /health_check
method: GET
- http:
path: /respond_400
method: POST
- http:
path: /throw_error
method: GET
SQSHandlerLambda:
role: SQSHandlerRole
handler: src/functions/sqs_listener/index.handler
environment:
SlackEndpoint: ${ssm:/demo/${opt:stage}/slack_endpoint}
events:
- sqs:
arn: !GetAtt
- DemoSQSQueue
- Arn
batchSize: 5
resources:
Resources:
SnsToQueueSqsPolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: "allow-sns-messages"
Effect: Allow
Principal: "*"
Resource: !GetAtt
- DemoSQSQueue
- Arn
Action: "SQS:SendMessage"
Condition:
ArnEquals:
"aws:SourceArn": !Ref DemoSnsTopic
Queues:
- Ref: DemoSQSQueue
SQSHandlerRole:
Type: AWS::IAM::Role
Properties:
Path: /${opt:stage}/demos/lambdaApiDemo/serviceRoles/
RoleName: PullMessagesRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: PullMessagesLambdaPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- 'Fn::Join':
- ':'
-
- 'arn:aws:logs'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'log-group:/aws/lambda/*:*:*'
- Effect: Allow
Action:
- sqs:ReceiveMessage
- sqs:DeleteMessage
- sqs:GetQueueAttributes
Resource: "*"
- Effect: Allow
Action:
- xray:PutTraceSegment
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: "*"
DemoLambdaRole:
Type: AWS::IAM::Role
Properties:
Path: /${opt:stage}/demos/lambdaApiDemo/serviceRoles/
RoleName: DemoLambdaRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: DemoLambdaPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- 'Fn::Join':
- ':'
-
- 'arn:aws:logs'
- Ref: 'AWS::Region'
- Ref: 'AWS::AccountId'
- 'log-group:/aws/lambda/*:*:*'
- Effect: Allow
Action:
- xray:PutTraceSegment
- xray:PutTraceSegments
- xray:PutTelemetryRecords
Resource: "*"
- Effect: Allow
Action:
- "dynamodb:*"
Resource: arn:aws:dynamodb:${self:provider.region}:#{AWS::AccountId}:table/DemoDynamodbTable-${opt:stage}
- Effect: Allow
Action:
- "sns:Publish"
Resource: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:demo-sns-topic-${opt:stage}
- Effect: Allow
Action:
- "ec2:DescribeNetworkInterfaces"
- "ec2:CreateNetworkInterface"
- "ec2:DeleteNetworkInterface"
- "ec2:DescribeInstances"
- "ec2:AttachNetworkInterface"
Resource: "*"
DemoDynamodbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: DemoDynamodbTable-${opt:stage}
AttributeDefinitions:
- AttributeName: UserEmail
AttributeType: S
- AttributeName: DateTime
AttributeType: S
KeySchema:
- AttributeName: UserEmail
KeyType: HASH
- AttributeName: DateTime
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
DemoSnsTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: demo-sns-topic-${opt:stage}
DemoSQSQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: demo-sqs-queue-${opt:stage}
QueueSubscription:
Type: 'AWS::SNS::Subscription'
Properties:
TopicArn: !Ref DemoSnsTopic
Endpoint: !GetAtt
- DemoSQSQueue
- Arn
Protocol: sqs
RawMessageDelivery: 'true'