/
serverless.yml
191 lines (175 loc) · 5.26 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
service: qldb-vpc
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs16.x
memorySize: 512
stage: ${opt:stage, 'dev'}
region: eu-west-1
stackName: ${self:service}
tracing:
apiGateway: true
lambda: true # Optional, can be true (true equals 'Active'), 'Active' or 'PassThrough'
environment:
AWS_NODEJS_CONNECTION_REUSE_ENABLED : "1"
LEDGER_NAME:
Ref: QLDBPrivateLedger
iamRoleStatements:
- Effect: Allow
Action:
- qldb:SendCommand
Resource: arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-private-${self:provider.stage}
plugins:
- serverless-iam-roles-per-function
- serverless-cloudformation-sub-variables
functions:
qldbPrivateTable:
name: qldb-private-table-${self:provider.stage}
handler: functions/createQldbTable.handler
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLCreateTable
Resource:
- !Sub 'arn:aws:qldb:${AWS::Region}:${AWS::AccountId}:ledger/qldb-private-${self:provider.stage}/*'
memorySize: 256
timeout: 15
environment:
LICENCE_TABLE_NAME: Test
createLicence:
name: qldb-private-${self:provider.stage}
handler: functions/create-licence.handler
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: Allow
Action:
- qldb:PartiQLInsert
- qldb:PartiQLSelect
- qldb:PartiQLUpdate
Resource:
- !Sub 'arn:aws:qldb:${AWS::Region}:${AWS::AccountId}:ledger/qldb-private-${self:provider.stage}/table/*'
events:
- http:
path: /licences
method: post
cors: true
vpc:
securityGroupIds:
- !GetAtt QLDBSecurityGroup.GroupId
subnetIds:
- Ref: QLDBSubnetA
- Ref: QLDBSubnetB
resources:
Resources:
QLDBPrivateLedger:
Type: AWS::QLDB::Ledger
Properties:
Name: qldb-private-${self:provider.stage}
DeletionProtection: false
PermissionsMode: STANDARD
Tags:
-
Key: name
Value: qldb-private
QLDBTable:
Type: Custom::qldbTable
DependsOn: QLDBPrivateLedger
Properties:
ServiceToken: !GetAtt QldbPrivateTableLambdaFunction.Arn
Version: 1.1 #change this to force redeploy
QLDBVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: qldb-private
QLDBSubnetA:
DependsOn: QLDBVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: QLDBVPC
AvailabilityZone: ${self:provider.region}a
CidrBlock: "10.0.2.0/24"
Tags:
- Key: Name
Value: qldb-private-a
QLDBSubnetB:
DependsOn: QLDBVPC
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: QLDBVPC
AvailabilityZone: ${self:provider.region}b
CidrBlock: "10.0.3.0/24"
Tags:
- Key: Name
Value: qldb-private-b
QLDBSecurityGroup:
DependsOn: QLDBVPC
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SecurityGroup for QLDB Private
VpcId:
Ref: QLDBVPC
Tags:
- Key: Name
Value: qldb-private-sg
VpcEndpointSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId:
Ref: QLDBVPC
GroupDescription: 'Security group for VPC Endpoint'
Tags:
- Key: Name
Value: qldb-vpce-sg
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
SourceSecurityGroupId: !GetAtt QLDBSecurityGroup.GroupId
QLDBEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS:
- arn:aws:iam::#{AWS::AccountId}:role/qldb-vpc-${self:provider.stage}-#{AWS::Region}-lambdaRole
Action:
- qldb:SendCommand
Resource: arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-private-${self:provider.stage}
- Effect: Allow
Principal:
AWS:
- arn:aws:iam::#{AWS::AccountId}:role/qldb-vpc-${self:provider.stage}-#{AWS::Region}-lambdaRole
Action:
- qldb:PartiQLInsert
- qldb:PartiQLSelect
- qldb:PartiQLUpdate
Resource: arn:aws:qldb:#{AWS::Region}:#{AWS::AccountId}:ledger/qldb-private-${self:provider.stage}/table/*
PrivateDnsEnabled: True
SecurityGroupIds:
- !GetAtt VpcEndpointSecurityGroup.GroupId
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.qldb.session'
SubnetIds:
- Ref: QLDBSubnetA
- Ref: QLDBSubnetB
VpcEndpointType: Interface
VpcId: !Ref QLDBVPC
Outputs:
QLDBSecurityGroupId:
Value: !Ref QLDBSecurityGroup
VpcEndpointSecurityGroupId:
Value: !Ref VpcEndpointSecurityGroup
SubnetIdA:
Value: !Ref QLDBSubnetA
SubnetIdB:
Value: !Ref QLDBSubnetB