-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
197 lines (180 loc) · 4.86 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
service: go-serverless-template
plugins:
- serverless-localstack
- serverless-go-plugin
custom:
serviceName: go-serverless-template
stage: ${opt:stage, 'local'}
region: us-east-1
helloQueueName: ${self:custom.serviceName}-${self:custom.stage}-hello-queue
helloSecondaryQueueName: ${self:custom.serviceName}-${self:custom.stage}-hello-secondary-queue
helloTopicName: ${self:custom.serviceName}-${self:custom.stage}-hello-topic
helloTableName: ${self:custom.serviceName}-${self:custom.stage}-hello-table
localstack:
stages:
- local
autostart: true
lambda:
mount_code: true
debug: true
go:
supportedRuntimes: ["provided.al2"]
buildProvidedRuntimeAsBootstrap: true
provider:
name: aws
region: ${self:custom.region}
stage: ${self:custom.stage}
apiName: ${self:custom.serviceName}-${self:provider.stage}
environment:
SNS_TOPIC: {"Ref": "HelloTopic"}
DYNAMODB_TABLE: ${self:custom.helloTableName}
memorySize: 128
apiGateway:
shouldStartNameWithService: true
iam:
role:
statements:
- Effect: Allow
Action:
- "sqs:SendMessage"
- "sqs:ReceiveMessage"
- "sqs:DeleteMessage"
- "sqs:GetQueueAttributes"
- "sqs:GetQueueUrl"
Resource:
- {"Fn::GetAtt": ["HelloQueue", "Arn"]}
- {"Fn::GetAtt": ["HelloSecondaryQueue", "Arn"]}
- Effect: Allow
Action:
- "sns:Publish"
Resource: {"Ref": "HelloTopic"}
- Effect: Allow
Action:
- "dynamodb:PutItem"
- "dynamodb:GetItem"
- "dynamodb:Query"
Resource: {"Fn::GetAtt": ["HelloTable", "Arn"]}
logs:
restApi:
executionLogging: true
level: INFO
fullExecutionData: true
httpApi:
accessLogging: true
executionLogging: true
frameworks:
lambda:
level: INFO
resources:
Resources:
HelloQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.helloQueueName}
HelloQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref HelloQueue
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: "*"
Action:
- "sqs:SendMessage"
- "sqs:ReceiveMessage"
- "sqs:DeleteMessage"
Resource: !GetAtt HelloQueue.Arn
HelloSecondaryQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: ${self:custom.helloSecondaryQueueName}
HelloSecondaryQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref HelloSecondaryQueue
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: "*"
Action:
- "sqs:SendMessage"
- "sqs:ReceiveMessage"
- "sqs:DeleteMessage"
Resource: !GetAtt HelloSecondaryQueue.Arn
HelloTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: ${self:custom.helloTopicName}
TopicName: ${self:custom.helloTopicName}
HelloSubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: sqs
TopicArn: {"Ref": "HelloTopic"}
Endpoint: !GetAtt HelloQueue.Arn
HelloSecondarySubscription:
Type: AWS::SNS::Subscription
Properties:
Protocol: sqs
TopicArn: {"Ref": "HelloTopic"}
Endpoint: !GetAtt HelloSecondaryQueue.Arn
HelloTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.helloTableName}
functions:
helloHttp:
handler: cmd/hello/http-adapter/main.go
runtime: provided.al2
events:
- http:
path: /hello/{name}
method: get
cors: true
request:
parameters:
paths:
name: true
helloPrimary:
handler: cmd/hello/primary-sqs-adapter/main.go
runtime: provided.al2
events:
- sqs:
arn: !GetAtt HelloQueue.Arn
batchSize: 1
helloSecondary:
handler: cmd/hello/secondary-sqs-adapter/main.go
runtime: provided.al2
events:
- sqs:
arn: !GetAtt HelloSecondaryQueue.Arn
batchSize: 1
outputs:
helloQueueUrl:
Value:
Ref: HelloQueue
helloSecondaryQueueUrl:
Value:
Ref: HelloSecondaryQueue
helloTopicArn:
Value:
Ref: HelloTopic
helloTableArn:
Value:
Fn::GetAtt:
- HelloTable
- Arn