-
Notifications
You must be signed in to change notification settings - Fork 5
/
serverless.yml
178 lines (174 loc) · 4.93 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
service: super-serverless-sample
frameworkVersion: '1.83.3'
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: us-east-1
environment:
VOTE_TABLE: vote-${opt:stage, self:provider.stage}
VOTE_BAG_TABLE: vote-bag-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- "sqs:SendMessage"
Resource: !GetAtt RegisterVoteDLQ.Arn
- Effect: Allow
Action:
- "sqs:SendMessage"
Resource: !GetAtt RegisterVoteQueue.Arn
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:DeleteItem
- dynamodb:DescribeStream
- dynamodb:ListStreams
Resource: "arn:aws:dynamodb:*:*:*"
- Effect: Allow
Action:
- rds-data:BatchExecuteStatement
- rds-data:BeginTransaction
- rds-data:CommitTransaction
- rds-data:ExecuteStatement
- rds-data:RollbackTransaction
Resource: arn:aws:rds:${self:provider.region}:*:cluster:*
tags:
product: super-serverless-sample
functions:
registerVote:
handler: handlers/vote_register.main
memorySize: 128
events:
- eventBridge:
pattern:
source:
- vote_register
detail-type:
- Vote
deadLetter:
targetArn:
GetResourceArn: RegisterVoteDLQ
counterVote:
handler: handlers/vote_counter.main
memorySize: 128
reservedConcurrency: 100
events:
- sqs:
arn:
Fn::GetAtt:
- RegisterVoteQueue
- Arn
batchSize: 100
environment:
RDS_ENDPOINT: {"Fn::GetAtt": ["VoteAnalyticsDatabase","Endpoint.Address"]}
custom:
apiGatewayServiceProxies:
- eventbridge:
path: /vote
method: post
source: 'vote_register'
detailType: 'Vote'
eventBusName: default
cors: true
vpcConfig:
cidrBlock: '10.0.0.0/16'
createNatGateway: 2
createNetworkAcl: false
createDbSubnet: true
createFlowLogs: false
createBastionHost: false
bastionHostKeyName: MyKey
createNatInstance: false
createParameters: false
zones:
- us-east-1a
- us-east-1b
- us-east-1c
services:
- kms
- secretsmanager
subnetGroups:
- rds
exportOutputs: false
resources:
Resources:
RegisterVoteQueue:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: "RegisterVoteQueue"
RegisterVoteDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: RegisterVote-dl-queue
VoteDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
TableName: ${self:provider.environment.VOTE_TABLE}
VoteAnalyticsDatabase:
Type: AWS::RDS::DBCluster
Properties:
BackupRetentionPeriod: 1
DBSubnetGroupName: !Ref RDSSubnetGroup #recurso criado automaticamente pelo plugin serverless-vpc-plugin
Engine: aurora-postgresql
EngineMode: serverless
MasterUsername: vote_analytics
DatabaseName: vote_analytics
MasterUserPassword: vote_analytics
EnableHttpEndpoint: true
ScalingConfiguration:
AutoPause: false
MinCapacity: 2
MaxCapacity: 2
StorageEncrypted: true
VpcSecurityGroupIds:
- !Ref AppSecurityGroup #recurso criado automaticamente pelo plugin serverless-vpc-plugin
SecurityGroupIngress:
Type: 'AWS::EC2::SecurityGroupIngress'
Properties:
GroupId: !Ref AppSecurityGroup
IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId: !GetAtt AppSecurityGroup.GroupId
SecurityGroupEgress:
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
GroupId: !Ref AppSecurityGroup
IpProtocol: tcp
FromPort: 5432
ToPort: 5432
SourceSecurityGroupId: !GetAtt AppSecurityGroup.GroupId
SecurityGroupEgress2:
Type: 'AWS::EC2::SecurityGroupEgress'
Properties:
GroupId: !Ref AppSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !GetAtt AppSecurityGroup.GroupId
RegisterVoteLambdaFunctionInvokeConfig:
Type: AWS::Lambda::EventInvokeConfig
Properties:
DestinationConfig:
OnSuccess:
Destination: !GetAtt RegisterVoteQueue.Arn
OnFailure:
Destination: !GetAtt RegisterVoteDLQ.Arn
FunctionName: !Ref RegisterVoteLambdaFunction
Qualifier: $LATEST
extensions:
CounterVoteEventSourceMappingSQSRegisterVoteQueue:
Properties:
MaximumBatchingWindowInSeconds: 1
plugins:
- serverless-apigateway-service-proxy
- serverless-plugin-lambda-dead-letter
- serverless-vpc-plugin