generated from Hack23/templateopensource
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yml
793 lines (793 loc) · 23.4 KB
/
template.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
AWSTemplateFormatVersion: "2010-09-09"
Description: "lambda in vpc with vpc endpoints"
Parameters:
GlobalTableArn:
Description: Provide Arn if global dynamodb table is deployed in different region
Type: String
Default: ''
DomainNamePrefix:
Description: Domain name prefix (optional), used to setup route53 dns
Type: String
Default: api
DomainName:
Description: Domain name (optional), used to setup route53 dns
Type: String
Default: hack23.com
VpcCidrPrefix:
Description: The first part of the CIDR block for the VPC and subnets
Type: String
Default: "10.1"
Conditions:
deployGlobalTable: !Equals
- ''
- !Ref 'GlobalTableArn'
Resources:
VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: !Sub "${VpcCidrPrefix}.0.0/16"
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: "Lamba vpc"
DefaultVPCSgIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !GetAtt "VPC.DefaultSecurityGroup"
Description: "Force removal of default vpc sg rules"
IpProtocol: "icmp"
CidrIp: 127.0.0.1/32
FromPort: 7
ToPort: 7
DefaultVPCSgEgress:
Type: AWS::EC2::SecurityGroupEgress
Properties:
GroupId: !GetAtt "VPC.DefaultSecurityGroup"
Description: "Force removal of default vpc sg rules"
IpProtocol: "icmp"
CidrIp: 127.0.0.1/32
FromPort: 7
ToPort: 7
PrivateSubnet1:
Type: "AWS::EC2::Subnet"
Properties:
CidrBlock: !Sub "${VpcCidrPrefix}.0.0/24"
MapPublicIpOnLaunch: false
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Subnet AZ A"
AvailabilityZone:
Fn::Select:
- "0"
- Fn::GetAZs:
Ref: "AWS::Region"
PrivateSubnet2:
Type: "AWS::EC2::Subnet"
Properties:
CidrBlock: !Sub "${VpcCidrPrefix}.1.0/24"
MapPublicIpOnLaunch: false
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Subnet AZ B"
AvailabilityZone:
Fn::Select:
- "1"
- Fn::GetAZs:
Ref: "AWS::Region"
PrivateSubnet3:
Type: "AWS::EC2::Subnet"
Properties:
CidrBlock: !Sub "${VpcCidrPrefix}.2.0/24"
MapPublicIpOnLaunch: false
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Subnet AZ C"
AvailabilityZone:
Fn::Select:
- "2"
- Fn::GetAZs:
Ref: "AWS::Region"
PrivateNetworkAcl:
Type: AWS::EC2::NetworkAcl
Properties:
VpcId: !Ref 'VPC'
Tags:
- Key: Application
Value: !Ref 'AWS::StackId'
- Key: Network
Value: Private
InboundPrivateNetworkAclEntry:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref 'PrivateNetworkAcl'
RuleNumber: '700'
Protocol: '6'
RuleAction: allow
Egress: 'false'
CidrBlock: '0.0.0.0/0'
PortRange:
From: '1024'
To: '65535'
InboundDenyRdpPrivateNetworkAclEntry:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref 'PrivateNetworkAcl'
RuleNumber: '70'
Protocol: '6'
RuleAction: deny
Egress: 'false'
CidrBlock: '0.0.0.0/0'
PortRange:
From: '3389'
To: '3389'
OutboundPrivateNetworkAclEntry:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId: !Ref 'PrivateNetworkAcl'
RuleNumber: '800'
Protocol: '6'
RuleAction: allow
Egress: 'true'
CidrBlock: '0.0.0.0/0'
PortRange:
From: '443'
To: '443'
PrivateSubnetNetworkAclAssociation1:
Type: AWS::EC2::SubnetNetworkAclAssociation
Properties:
SubnetId: !Ref 'PrivateSubnet1'
NetworkAclId: !Ref 'PrivateNetworkAcl'
PrivateSubnetNetworkAclAssociation2:
Type: AWS::EC2::SubnetNetworkAclAssociation
Properties:
SubnetId: !Ref 'PrivateSubnet2'
NetworkAclId: !Ref 'PrivateNetworkAcl'
PrivateSubnetNetworkAclAssociation3:
Type: AWS::EC2::SubnetNetworkAclAssociation
Properties:
SubnetId: !Ref 'PrivateSubnet3'
NetworkAclId: !Ref 'PrivateNetworkAcl'
RouteTablePrivate1:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Route Table A"
RouteTablePrivate1Association1:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId:
Ref: "RouteTablePrivate1"
SubnetId:
Ref: "PrivateSubnet1"
RouteTablePrivate2:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Route Table B"
RouteTablePrivate2Association1:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId:
Ref: "RouteTablePrivate2"
SubnetId:
Ref: "PrivateSubnet2"
RouteTablePrivate3:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId:
Ref: "VPC"
Tags:
- Key: "Name"
Value: "Private Route Table C"
RouteTablePrivate3Association1:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId:
Ref: "RouteTablePrivate3"
SubnetId:
Ref: "PrivateSubnet3"
EncryptionKey:
Type: AWS::KMS::Key
Properties:
Description: Key used for for stack
Enabled: true
EnableKeyRotation: true
KeyPolicy:
Statement:
- Sid: manage-key-stack
Action:
- kms:*
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:role/GithubWorkFlowRole'
Resource: '*'
- Sid: manage-key-root
Action:
- kms:*
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Resource: '*'
- Sid: logs-access-policy-statement
Action:
- kms:*
Effect: Allow
Principal:
Service: logs.amazonaws.com
Resource: '*'
- Sid: api-access-policy-statement
Action:
- kms:*
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Resource: '*'
DNSFIrewallDomainsList:
Type: AWS::Route53Resolver::FirewallDomainList
Properties:
Domains:
- '*.amazonaws.com'
Name: AwsDomains
DNSFIrewallAllDomainsList:
Type: AWS::Route53Resolver::FirewallDomainList
Properties:
Domains:
- '*'
Name: AllDomains
DNSFIrewallRuleGroup:
Type: AWS::Route53Resolver::FirewallRuleGroup
Properties:
FirewallRules:
-
Action: ALLOW
FirewallDomainListId: !Ref DNSFIrewallDomainsList
Priority: 1
-
Action: BLOCK
BlockResponse: NODATA
FirewallDomainListId: !Ref DNSFIrewallAllDomainsList
Priority: 2
DNSFIrewalluleGroupAssociation:
Type: AWS::Route53Resolver::FirewallRuleGroupAssociation
Properties:
FirewallRuleGroupId: !Ref DNSFIrewallRuleGroup
Name: 'DNSFIrewallRuleGroupAssociation'
Priority: 101
VpcId: !Ref VPC
FlowLogs:
Type: "AWS::EC2::FlowLog"
Properties:
ResourceType: "VPC"
ResourceId:
Ref: "VPC"
TrafficType: "ALL"
LogDestinationType: "cloud-watch-logs"
LogGroupName: "vpcprivate"
DeliverLogsPermissionArn:
Fn::GetAtt:
- "IamRoleForFlowLogs"
- "Arn"
IamRoleForFlowLogs:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- vpc-flow-logs.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
VPCEndpoint:
Type: "AWS::EC2::VPCEndpoint"
Properties:
VpcEndpointType: "Interface"
ServiceName:
Fn::Join:
- ""
-
- "com.amazonaws."
- Ref: "AWS::Region"
- ".ec2"
VpcId:
Ref: "VPC"
PrivateDnsEnabled: true
SecurityGroupIds:
- Ref: "SgForVPCEndpoint"
SubnetIds:
- !Ref "PrivateSubnet1"
- !Ref "PrivateSubnet2"
- !Ref "PrivateSubnet3"
SgForVPCEndpoint:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Security group to allow access to ec2 VPC Endpoint"
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref "LambdaSecurityGroup"
IpProtocol: "tcp"
FromPort: "443"
ToPort: "443"
Description: "Allow inbound https from inside vpc"
SecurityGroupEgress:
- CidrIp: "10.1.0.0/16"
IpProtocol: "tcp"
FromPort: "443"
ToPort: "443"
Description: "Allow outbound https inside vpc"
VpcId:
Ref: "VPC"
VPCEndpointS3:
Type: "AWS::EC2::VPCEndpoint"
Properties:
ServiceName:
Fn::Join:
- ""
-
- "com.amazonaws."
- Ref: "AWS::Region"
- ".s3"
VpcId:
Ref: "VPC"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal: "*"
Action:
- "*"
Resource:
- "*"
RouteTableIds:
- Ref: "RouteTablePrivate1"
- Ref: "RouteTablePrivate2"
- Ref: "RouteTablePrivate3"
VPCEndpointDynamoDb:
Type: "AWS::EC2::VPCEndpoint"
Properties:
ServiceName:
Fn::Join:
- ""
-
- "com.amazonaws."
- Ref: "AWS::Region"
- ".dynamodb"
VpcId:
Ref: "VPC"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
AWS: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:root"
Action:
- "dynamodb:ListTables"
Resource:
- !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/global-table'
RouteTableIds:
- Ref: "RouteTablePrivate1"
- Ref: "RouteTablePrivate2"
- Ref: "RouteTablePrivate3"
LambdaSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Lambda Traffic"
VpcId: !Ref "VPC"
SecurityGroupEgress:
- IpProtocol: "tcp"
FromPort: "443"
ToPort: "443"
CidrIp: "10.1.0.0/16"
Description: "Allow outbound https inside vpc"
InstanceSecurityGroupIngress:
Type: "AWS::EC2::SecurityGroupIngress"
Properties:
GroupId: !Ref "LambdaSecurityGroup"
IpProtocol: "tcp"
FromPort: "443"
ToPort: "443"
Description: "Allow inbound https"
SourceSecurityGroupId: !Ref "LambdaSecurityGroup"
LambdaFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
- "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole"
- "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
- "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
- "arn:aws:iam::aws:policy/AmazonSNSFullAccess"
- "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
DeadLetterTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: 'admin@hack23.com'
Protocol: email
KmsMasterKeyId: alias/aws/sns
Lambda:
Type: "AWS::Lambda::Function"
Properties:
Code:
ZipFile: |
exports.handler = async function(event, context) {
const audit = { "RequestId": context.awsRequestId , "Action": "Healthcheck", "Actor": "Api", statusCode: 200}
console.info("EVENT : " + JSON.stringify(audit, null, 2));
return "OK";
}
Description: "lambda"
FunctionName: audittest
Handler: index.handler
Architectures:
- arm64
MemorySize: 256
ReservedConcurrentExecutions: 4
DeadLetterConfig:
TargetArn: !Ref "DeadLetterTopic"
PackageType: "Zip"
Role: !GetAtt LambdaFunctionRole.Arn
Runtime: "nodejs20.x"
Timeout: 30
VpcConfig:
SecurityGroupIds:
- !Ref "LambdaSecurityGroup"
SubnetIds:
- !Ref "PrivateSubnet1"
- !Ref "PrivateSubnet2"
- !Ref "PrivateSubnet3"
LambdaDynamo:
Type: "AWS::Lambda::Function"
Properties:
Code:
ZipFile: |
const { DynamoDB } = require("@aws-sdk/client-dynamodb");
let region = process.env.AWS_REGION;
const client = new DynamoDB({ region: region });
exports.handler = async function(event, context) {
const audit = { "RequestId": context.awsRequestId , "Action": "Write", "Actor": "Api", statusCode: 200}
console.info("EVENT : " + JSON.stringify(audit, null, 2));
return "OK";
}
Description: "crud"
FunctionName: database
Handler: index.handler
Architectures:
- arm64
MemorySize: 256
ReservedConcurrentExecutions: 4
DeadLetterConfig:
TargetArn: !Ref "DeadLetterTopic"
PackageType: "Zip"
Role: !GetAtt LambdaFunctionRole.Arn
Runtime: "nodejs20.x"
Timeout: 30
VpcConfig:
SecurityGroupIds:
- !Ref "LambdaSecurityGroup"
SubnetIds:
- !Ref "PrivateSubnet1"
- !Ref "PrivateSubnet2"
- !Ref "PrivateSubnet3"
GlobalTable:
Type: AWS::DynamoDB::GlobalTable
Condition: deployGlobalTable
Properties:
TableName: global-table
BillingMode: PAY_PER_REQUEST
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
Replicas:
- PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
Region: eu-west-1
- PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
Region: eu-central-1
AttributeDefinitions:
- AttributeName: primary_key
AttributeType: S
KeySchema:
- AttributeName: primary_key
KeyType: HASH
RestApi:
Type: AWS::ApiGateway::RestApi
Properties:
ApiKeySourceType: HEADER
DisableExecuteApiEndpoint: False #
EndpointConfiguration:
Types:
- REGIONAL
Name: ApiName
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: 'admin@hack23.com'
Protocol: email
KmsMasterKeyId: alias/aws/sns
RestApiGw4xxErrorsAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmActions:
- !Ref 'AlarmTopic'
AlarmDescription: Alarm that tracks the percentage of 4xx responses received from REST API Gateway
responses
AlarmName: RestApiGw4xxErrorsAlarm
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 5
DatapointsToAlarm: 3
Metrics:
- Id: m1
MetricStat:
Metric:
MetricName: 4XXError
Namespace: AWS/ApiGateway
Dimensions:
- Name: ApiName
Value: ApiName
Period: 60
Stat: Average
ReturnData: false
- Expression: 100 * m1
Id: percent4xx
Label: Percent 4xx
Threshold: 20
TreatMissingData: missing
ApiResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt RestApi.RootResourceId
PathPart: "healthcheck"
RestApiId: !Ref RestApi
HealthCheckMethod:
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: GET
Integration:
ConnectionType: INTERNET
Credentials: !GetAtt ApiRole.Arn
IntegrationHttpMethod: POST
IntegrationResponses:
- StatusCode: 200
ResponseTemplates:
application/json: ""
ResponseParameters:
method.response.header.Strict-Transport-Security: "'max-age=31536000; includeSubDomains'"
method.response.header.X-Content-Type-Options: "'nosniff'"
method.response.header.Cache-Control: "'no-store, no-cache, must-revalidate, private'"
Type: AWS
Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Lambda.Arn}/invocations'
# RequestValidatorId: !Ref ApiRequestValidator
RequestModels:
application/json:
!Ref RequestModel
MethodResponses:
- StatusCode: 200
ResponseModels:
application/json: Empty
ResponseParameters:
method.response.header.Strict-Transport-Security: true
method.response.header.X-Content-Type-Options: true
method.response.header.Cache-Control: true
OperationName: 'lambda'
ResourceId: !Ref ApiResource
RestApiId: !Ref RestApi
RequestModel:
Type: AWS::ApiGateway::Model
Properties:
ContentType: 'application/json'
RestApiId: !Ref RestApi
Schema: {"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Stats",
"type": "object" }
ApiLoggingGroup:
Type: "AWS::Logs::LogGroup"
Properties:
KmsKeyId: !GetAtt "EncryptionKey.Arn"
RetentionInDays: 30
CloudWatchRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs'
ApiCloudwatchRoleArn:
Type: AWS::ApiGateway::Account
Properties:
CloudWatchRoleArn: !GetAtt CloudWatchRole.Arn
ApiStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref ApiDeployment
Description: "API Stage v1"
RestApiId: !Ref RestApi
StageName: "v1"
CacheClusterEnabled: False
CacheClusterSize: "0.5"
TracingEnabled: True
MethodSettings:
- HttpMethod: "*"
ResourcePath: "/*"
CachingEnabled: False
CacheTtlInSeconds: 60
DataTraceEnabled: True
MetricsEnabled: True
CacheDataEncrypted: True
LoggingLevel: "INFO"
AccessLogSetting:
DestinationArn:
!GetAtt "ApiLoggingGroup.Arn"
Format: "$context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] $context.httpMethod $context.resourcePath $context.protocol $context.status $context.responseLength $context.requestId $context.extendedRequestId"
ApiRequestValidator:
Type: AWS::ApiGateway::RequestValidator
Properties:
Name: "RequestValidator"
RestApiId: !Ref RestApi
ValidateRequestBody: True
ValidateRequestParameters: False
ApiDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: HealthCheckMethod
Properties:
RestApiId: !Ref RestApi
ApiRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: 'Allow'
Principal:
Service:
- 'apigateway.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyName: "ApiRolePolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action: 'lambda:*'
Resource: !GetAtt Lambda.Arn
ApiUserPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Allows user to trigger the test API
ManagedPolicyName: !Sub "ApiUserPolicy${AWS::Region}"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- execute-api:Invoke
- execute-api:ManageConnections
Resource:
- !Join ['',[!Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:',!Ref RestApi, '*']]
RestApiDomainCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
CertificateTransparencyLoggingPreference: ENABLED
DomainName: !Join
- ''
- - '*'
- .
- !Ref 'DomainName'
- ''
ValidationMethod: DNS
RestApiDomainName:
Type: 'AWS::ApiGateway::DomainName'
Properties:
RegionalCertificateArn: !Ref RestApiDomainCertificate
SecurityPolicy: "TLS_1_2"
EndpointConfiguration:
Types:
- "REGIONAL"
DomainName: !Join
- ''
- - !Ref 'DomainNamePrefix'
- .
- !Ref 'DomainName'
- ''
RestApiMapping:
Type: 'AWS::ApiGateway::BasePathMapping'
Properties:
DomainName: !Ref RestApiDomainName
RestApiId: !Ref RestApi
HealthCheckRestApi:
Type: 'AWS::Route53::HealthCheck'
Properties:
HealthCheckConfig:
Port: 443
Type: HTTPS
EnableSNI: True
ResourcePath: !Sub "${ApiStage}/healthcheck"
FullyQualifiedDomainName: !Sub "${RestApi}.execute-api.${AWS::Region}.amazonaws.com"
RequestInterval: 10
FailureThreshold: 1
Metadata: {}
Outputs:
HealthCheckId:
Value: !GetAtt HealthCheckRestApi.HealthCheckId
AliasTargetHostedZoneId:
Value: !GetAtt RestApiDomainName.RegionalHostedZoneId
AliasTargetDNSName:
Value: !GetAtt RestApiDomainName.RegionalDomainName
ApiRoleName:
Value: !Ref ApiRole
StackId:
Value: !Ref AWS::StackId
RestApi:
Value: RestApi
HealthcheckFunction:
Value: Lambda
DynamoFunction:
Value: LambdaDynamo
DeadLetterTopic:
Value: DeadLetterTopic
AlarmTopic:
Value: AlarmTopic
GlobalTable:
Value: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/global-table'
GlobalTableIndex:
Value: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/global-table'
GlobalTableStream:
Value: !Sub 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/global-table'
GlobalTableZoneIrland:
Value: !Sub 'arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/global-table'
GlobalTableIndexIrland:
Value: !Sub 'arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/global-table'
GlobalTableStreamIrland:
Value: !Sub 'arn:aws:dynamodb:eu-west-1:${AWS::AccountId}:table/global-table'
GlobalTableZoneFrankfurt:
Value: !Sub 'arn:aws:dynamodb:eu-central-1:${AWS::AccountId}:table/global-table'
GlobalTableIndexFrankfurt:
Value: !Sub 'arn:aws:dynamodb:eu-central-1:${AWS::AccountId}:table/global-table'
GlobalTableStreamFrankfurt:
Value: !Sub 'arn:aws:dynamodb:eu-central-1:${AWS::AccountId}:table/global-table'
ApiStageArn2:
Value: !Sub 'arn:aws:apigateway:${AWS::Region}::/restapis/${RestApi}/stages/${ApiStage}'
HealthCheckUrl:
Value: !Sub "https://${DomainNamePrefix}.${DomainName}/${ApiStage}/healthcheck"
ApiEndpointDomain:
Value: !Join
- ''
- - !Ref 'DomainNamePrefix'
- .
- !Ref 'DomainName'
- ''