-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverless.yml
178 lines (173 loc) · 4.75 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: autorizador-debito-cartao
provider:
name: aws
runtime: python3.8
region: us-east-1
stage: dev
stackName: ${self:service}-${self:provider.stage}
environment:
LANCAMENTO_TABLE: lancamento-${opt:stage, self:provider.stage}
CONTABILIZACAO_TABLE: contabilizacao-${opt:stage, self:provider.stage}
iamRoleStatements:
- 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:*
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource: "*"
- Effect: Allow
Action:
- events:PutEvents
Resource: "*"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- s3:GetObject
Resource: "*"
functions:
debitador:
handler: debitador.main
memorySize: 128
events:
- http:
path: debito
method: post
environment:
RDS_ENDPOINT: {"Fn::GetAtt": ["Database","Endpoint.Address"]}
criarConta:
handler: criar_conta.main
memorySize: 128
events:
- http:
path: conta
method: post
environment:
RDS_ENDPOINT: {"Fn::GetAtt": ["Database","Endpoint.Address"]}
registrarLancamento:
handler: registrar_lancamento.main
memorySize: 128
events:
- eventBridge:
pattern:
source:
- debitador
contabilizar:
handler: contabilizar.main
memorySize: 128
events:
- eventBridge:
pattern:
source:
- debitador
custom:
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:
Database:
Type: AWS::RDS::DBCluster
Properties:
BackupRetentionPeriod: 1
DBSubnetGroupName: !Ref RDSSubnetGroup #recurso criado automaticamente pelo plugin serverless-vpc-plugin
Engine: aurora-postgresql
EngineMode: serverless
MasterUsername: autorizador
DatabaseName: autorizador
MasterUserPassword: autorizador
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
LancamentoDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: "NEW_AND_OLD_IMAGES"
TableName: ${self:provider.environment.LANCAMENTO_TABLE}
ContabilizacaoDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: "NEW_AND_OLD_IMAGES"
TableName: ${self:provider.environment.CONTABILIZACAO_TABLE}
plugins:
- serverless-apigateway-service-proxy
- serverless-cloudformation-sub-variables
- serverless-vpc-plugin