-
Notifications
You must be signed in to change notification settings - Fork 0
/
formation.yml
295 lines (284 loc) · 8.9 KB
/
formation.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
AWSTemplateFormatVersion: 2010-09-09
Description: finix-transfer Service Deployment
Parameters:
Partner:
Type: String
Description: The partner you're deploying to.
Stage:
Type: String
Description: The stage you're deploying to.
Repository:
Type: String
Description: The Repository for this Service
Default: finix-transfer-service
ServiceName:
Type: String
Description: The Name for this Service
Default: finix-transfer
ServiceType:
Type: String
Description: The Type of this Service
Default: service
EndpointKey:
Type: String
Description: The Endpoint key of this Service
Default: transfer
AuthorizerService:
Type: String
Description: The Authorizer for this Service
Default: vpc-authorizer
DomainVersion:
Type: String
Description: The version number of the domain to used
Default: 1
TargetMode:
Type: String
Description: The Deployment Mode
Default: standard
AllowedValues:
- standard
- '-new'
- '-old'
Conditions:
isStandard: !Equals [ !Ref TargetMode, standard]
Resources:
# Resources that change service to service
Lambda:
Properties:
Code:
S3Bucket: '{{resolve:ssm:pt-global-codepipeline-bucket}}'
S3Key: !Sub 'code/${Repository}-${Partner}-${Stage}/my-deployment-package.zip'
Environment:
Variables:
PARTNER: !Sub '${Partner}'
STAGE: !Sub '${Stage}'
FunctionName: !Sub '${Repository}-${Partner}-${Stage}'
Handler: lambda_function.lambda_handler
Role: !Sub '{{resolve:ssm:pt-account-${Repository}-role}}'
Runtime: python3.8
MemorySize: 10240
VpcConfig:
SecurityGroupIds:
- !Sub '{{resolve:ssm:pt-partner-${Partner}-vpc-open-ingress-security}}'
SubnetIds:
- !Sub '{{resolve:ssm:pt-partner-${Partner}-vpc-web-subnet-1}}'
- !Sub '{{resolve:ssm:pt-partner-${Partner}-vpc-web-subnet-2}}'
- !Sub '{{resolve:ssm:pt-partner-${Partner}-vpc-web-subnet-3}}'
Type: 'AWS::Lambda::Function'
DynamoDB:
Type: 'AWS::DynamoDB::Table'
Properties:
StreamSpecification:
StreamViewType: NEW_IMAGE
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
TableName: !Sub '${Repository}-${Partner}-${Stage}'
# Common Routing
GetRoute:
DependsOn:
- ApiGateway
- RouteIntegration
- Authorizer
Properties:
ApiId: !Ref ApiGateway
AuthorizationType: CUSTOM
AuthorizerId: !Ref Authorizer
RouteKey: !Sub 'GET /${EndpointKey}'
Target: !Join
- /
- - integrations
- !Ref RouteIntegration
Type: 'AWS::ApiGatewayV2::Route'
RouteIntegration:
DependsOn:
- ApiGateway
Properties:
ApiId: !Ref ApiGateway
IntegrationType: AWS_PROXY
PayloadFormatVersion: '2.0'
IntegrationUri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${Repository}-${Partner}-${Stage}/invocations'
Type: 'AWS::ApiGatewayV2::Integration'
# Standard Finix Feed Resource
FinixFeedEvent:
DependsOn:
- Lambda
Type: AWS::Lambda::EventSourceMapping
Properties:
BatchSize: 1
EventSourceArn: !Sub '{{resolve:ssm:webhook-service-${Partner}-${Stage}-finix-webhook-stream}}'
FunctionName: !Sub '${Repository}-${Partner}-${Stage}'
StartingPosition: LATEST
# Common Microservice Resource Patterns
ApiGateway:
DependsOn:
- Lambda
Properties:
Name: !Sub '${Repository}-${Partner}-${Stage}'
ProtocolType: HTTP
CorsConfiguration:
AllowCredentials: false
AllowHeaders:
- x-api-key
AllowMethods:
- GET
- OPTIONS
- POST
- PUT
AllowOrigins:
- '*'
ExposeHeaders:
- x-api-key
MaxAge: 90
Type: 'AWS::ApiGatewayV2::Api'
ApiGatewayPermission:
Type: "AWS::Lambda::Permission"
DependsOn:
- ApiGateway
- Lambda
Properties:
Action: "lambda:InvokeFunction"
FunctionName: !GetAtt Lambda.Arn
Principal:
Fn::Join:
- ""
- - "apigateway."
- Ref: "AWS::URLSuffix"
ApiGatewayStage:
DependsOn:
- ApiGateway
Properties:
ApiId: !Ref ApiGateway
StageName: latest
Type: 'AWS::ApiGatewayV2::Stage'
Route53:
Type: 'AWS::Route53::RecordSet'
Properties:
HostedZoneId: !Sub '{{resolve:ssm:hosted-zone-${Stage}}}'
Name: !If [
isStandard,
!Sub "${Partner}.${ServiceName}.${ServiceType}.${Stage}.com",
!Sub "${Partner}${TargetMode}.${ServiceName}.${ServiceType}.${Stage}.com" ]
Type: 'A'
AliasTarget:
DNSName: !Sub '{{resolve:ssm:pt-account-${Repository}-${Stage}-distribution}}'
HostedZoneId: !Sub '{{resolve:ssm:pt-account-${Repository}-${Stage}-zone}}'
ApiMapping:
Type: 'AWS::ApiGatewayV2::ApiMapping'
DependsOn:
- ApiGateway
- ApiGatewayStage
Properties:
DomainName: !Sub '*.${ServiceName}.${ServiceType}.${Stage}.com'
ApiId: !Ref ApiGateway
ApiMappingKey: !Sub '${Partner}'
Stage: !Ref ApiGatewayStage
Authorizer:
Type: 'AWS::ApiGatewayV2::Authorizer'
Properties:
Name: !Sub '${AuthorizerService}-${Partner}-${Stage}'
ApiId: !Ref ApiGateway
AuthorizerType: REQUEST
AuthorizerCredentialsArn: !Sub '{{resolve:ssm:pt-account-${AuthorizerService}-role}}'
EnableSimpleResponses: true
AuthorizerPayloadFormatVersion: 2.0
AuthorizerUri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AuthorizerService}-${Partner}-${Stage}/invocations'
IdentitySource:
- $request.header.Authorization
DependsOn:
- ApiGateway
CodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub 'cb-${Repository}-${Partner}-${Stage}'
Description: !Sub '${Repository} service build'
ServiceRole: !Sub '{{resolve:ssm:pt-global-codebuild-role}}'
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: 'aws/codebuild/standard:5.0'
EnvironmentVariables:
- Name: STAGE
Type: PLAINTEXT
Value: !Sub '${Stage}'
- Name: PARTNER
Type: PLAINTEXT
Value: !Sub '${Partner}'
Source:
Type: CODEPIPELINE
TimeoutInMinutes: 20
CodePipeline:
DependsOn:
- CodeBuild
Type: 'AWS::CodePipeline::Pipeline'
Properties:
Name: !Sub 'cb-${Repository}-${Partner}-${Stage}'
RoleArn: !Sub '{{resolve:ssm:pt-global-codepipeline-role}}'
Stages:
- Name: Source
Actions:
- InputArtifacts: []
Name: Source
ActionTypeId:
Version: "1"
Owner: AWS
Category: Source
Provider: CodeStarSourceConnection
OutputArtifacts:
- Name: SourceArtifact
RunOrder: 1
Configuration:
ConnectionArn: !Sub '{{resolve:ssm:pt-global-github-connection}}'
FullRepositoryId: !Sub 'pay-theory/${Repository}'
BranchName: !If [ isStandard, !Sub '${Partner}-${Stage}', !Sub '${Partner}${TargetMode}-${Stage}' ]
OutputArtifactFormat: "CODE_ZIP"
- Name: Deploy
Actions:
- Name: !Sub 'cd-${Repository}-${Partner}-${Stage}'
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
InputArtifacts:
- Name: SourceArtifact
Configuration:
ProjectName: !Ref CodeBuild
RunOrder: 1
ArtifactStore:
Type: S3
Location: !Sub '{{resolve:ssm:pt-global-codepipeline-bucket}}'
# Final deploy
Deployment:
DependsOn:
- Lambda
- ApiGateway
- ApiGatewayStage
- RouteIntegration
- DynamoDB
- GetRoute
Properties:
ApiId: !Ref ApiGateway
StageName: latest
Type: 'AWS::ApiGatewayV2::Deployment'
# Final deploy
FinalDeployment:
DependsOn:
- Deployment
Properties:
Description: Cloudformation Final Deployment
ApiId: !Ref ApiGateway
StageName: latest
Type: 'AWS::ApiGatewayV2::Deployment'
Outputs:
Renew:
Description: Trigger to update/rebuild formation
Value: 'Mar 14 2022'