Skip to content

Commit c2c5fcc

Browse files
committed
cfn changes
1 parent 23fa3e5 commit c2c5fcc

File tree

2 files changed

+11
-193
lines changed

2 files changed

+11
-193
lines changed

cloudformation/custom-domain.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
Parameters:
2-
GWCertArn:
3-
Description: Certificate ARN
4-
Type: String
52
GWBaseDomainName:
63
Description: Base domain name
74
Type: String
8-
GWApiId:
9-
Description: API ID
10-
Type: String
11-
GWHostedZoneId:
12-
Description: Hosted Zone ID
13-
Type: String
145
RunEnvironment:
156
Type: String
167
AllowedValues: [ 'dev', 'prod' ]
@@ -23,22 +14,6 @@ Conditions:
2314
IsDev: !Equals [!Ref RunEnvironment, 'dev']
2415

2516
Resources:
26-
CustomDomainName:
27-
Type: AWS::ApiGateway::DomainName
28-
Properties:
29-
RegionalCertificateArn: !Ref GWCertArn
30-
EndpointConfiguration:
31-
Types:
32-
- REGIONAL
33-
DomainName: !Sub "${RecordName}.${GWBaseDomainName}"
34-
SecurityPolicy: TLS_1_2
35-
36-
CDApiMapping:
37-
Type: 'AWS::ApiGatewayV2::ApiMapping'
38-
Properties:
39-
DomainName: !Ref CustomDomainName
40-
ApiId: !Ref GWApiId
41-
Stage: default
4217

4318
CDRoute53RecordSetDev:
4419
Condition: IsDev

cloudformation/main.yml

Lines changed: 11 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ Resources:
117117
- ApiGwConfig
118118
- !Ref RunEnvironment
119119
- EnvDomainName
120-
GWCertArn: !FindInMap
121-
- ApiGwConfig
122-
- !Ref RunEnvironment
123-
- EnvCertificateArn
124-
GWApiId: !Ref AppApiGateway
125-
GWHostedZoneId:
126-
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
127120
CloudfrontDomain: !GetAtt [AppIcalCloudfrontDistribution, DomainName]
128121

129122
CoreUrlProd:
@@ -137,13 +130,6 @@ Resources:
137130
- ApiGwConfig
138131
- !Ref RunEnvironment
139132
- EnvDomainName
140-
GWCertArn: !FindInMap
141-
- ApiGwConfig
142-
- !Ref RunEnvironment
143-
- EnvCertificateArn
144-
GWApiId: !Ref AppApiGateway
145-
GWHostedZoneId:
146-
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
147133
CloudfrontDomain: !GetAtt [AppFrontendCloudfrontDistribution, DomainName]
148134

149135
AppLambdaUrl:
@@ -210,12 +196,6 @@ Resources:
210196
!Ref AWS::NoValue,
211197
]
212198
Events:
213-
ApiEvent:
214-
Type: Api
215-
Properties:
216-
RestApiId: !Ref AppApiGateway
217-
Path: /{proxy+}
218-
Method: ANY
219199
WarmingSchedule:
220200
Type: Schedule
221201
Properties:
@@ -544,120 +524,6 @@ Resources:
544524
AttributeName: "expireAt"
545525
Enabled: true
546526

547-
AppApiGateway:
548-
Type: AWS::Serverless::Api
549-
DependsOn:
550-
- AppApiLambdaFunction
551-
Properties:
552-
Name: !Sub ${ApplicationPrefix}-gateway
553-
Description: !Sub "${ApplicationFriendlyName} API Gateway"
554-
MinimumCompressionSize: 2048 # 2kb to compress
555-
AlwaysDeploy: True
556-
DefinitionBody:
557-
Fn::Transform:
558-
Name: AWS::Include
559-
Parameters:
560-
Location: ./phony-swagger.yml
561-
Route53:
562-
HostedZoneId:
563-
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
564-
StageName: default
565-
EndpointConfiguration:
566-
Type: REGIONAL
567-
Cors:
568-
AllowHeaders: "'Content-Type,Authorization,X-Amz-Date'"
569-
AllowOrigin: "'*'"
570-
MaxAge: "'300'"
571-
572-
APIDefault4XXResponse:
573-
Type: AWS::ApiGateway::GatewayResponse
574-
Properties:
575-
RestApiId: !Ref AppApiGateway
576-
ResponseType: DEFAULT_4XX
577-
StatusCode: "404"
578-
ResponseParameters:
579-
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
580-
ResponseTemplates:
581-
application/json: '{"error": true, "message": "Resource not found. Check your URL or contact support."}'
582-
583-
APIAccessDeniedResponse:
584-
Type: AWS::ApiGateway::GatewayResponse
585-
Properties:
586-
RestApiId: !Ref AppApiGateway
587-
ResponseType: ACCESS_DENIED
588-
StatusCode: "403"
589-
ResponseParameters:
590-
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
591-
ResponseTemplates:
592-
application/json: '{"error": true, "message": "Access denied. Perhaps reauthenticate and try again?"}'
593-
594-
APIUnauthorizedResponse:
595-
Type: AWS::ApiGateway::GatewayResponse
596-
Properties:
597-
RestApiId: !Ref AppApiGateway
598-
ResponseType: UNAUTHORIZED
599-
StatusCode: "401"
600-
ResponseParameters:
601-
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
602-
ResponseTemplates:
603-
application/json: '{"error": true, "message": "Request could not be authenticated. Perhaps reauthenticate and try again?"}'
604-
605-
AppApiGatewayLatencyAlarm:
606-
Type: "AWS::CloudWatch::Alarm"
607-
Condition: IsProd
608-
Properties:
609-
AlarmName: !Sub ${ApplicationPrefix}-gateway-latency-high
610-
AlarmDescription: "Trailing Mean - 95% API gateway latency is > 1.25s for 2 times in 4 minutes."
611-
Namespace: "AWS/ApiGateway"
612-
MetricName: "Latency"
613-
ExtendedStatistic: "tm95"
614-
Period: "120"
615-
EvaluationPeriods: "2"
616-
ComparisonOperator: "GreaterThanThreshold"
617-
Threshold: "1250"
618-
AlarmActions:
619-
- !Ref AlertSNSArn
620-
Dimensions:
621-
- Name: "ApiName"
622-
Value: !Sub ${ApplicationPrefix}-gateway
623-
624-
AppApiGatewayNoRequestsAlarm:
625-
Type: "AWS::CloudWatch::Alarm"
626-
Condition: IsProd
627-
Properties:
628-
AlarmName: !Sub ${ApplicationPrefix}-gateway-no-requests
629-
AlarmDescription: "No requests have been received in the past 5 minutes."
630-
Namespace: "AWS/ApiGateway"
631-
MetricName: "Count"
632-
Statistic: "Sum"
633-
Period: "300"
634-
EvaluationPeriods: "1"
635-
ComparisonOperator: "LessThanThreshold"
636-
Threshold: "1"
637-
AlarmActions:
638-
- !Ref PriorityAlertSNSArn
639-
Dimensions:
640-
- Name: "ApiName"
641-
Value: !Sub ${ApplicationPrefix}-gateway
642-
643-
AppApiGateway5XXErrorAlarm:
644-
Type: "AWS::CloudWatch::Alarm"
645-
Condition: IsProd
646-
Properties:
647-
AlarmName: !Sub ${ApplicationPrefix}-gateway-5xx
648-
AlarmDescription: "More than 2 API gateway 5XX errors were detected."
649-
Namespace: "AWS/ApiGateway"
650-
MetricName: "5XXError"
651-
Statistic: "Average"
652-
Period: "60"
653-
EvaluationPeriods: "1"
654-
ComparisonOperator: "GreaterThanThreshold"
655-
Threshold: "2"
656-
AlarmActions:
657-
- !Ref PriorityAlertSNSArn
658-
Dimensions:
659-
- Name: "ApiName"
660-
Value: !Sub ${ApplicationPrefix}-gateway
661527

662528
AppDLQMessagesAlarm:
663529
Type: "AWS::CloudWatch::Alarm"
@@ -678,23 +544,6 @@ Resources:
678544
AlarmActions:
679545
- !Ref PriorityAlertSNSArn
680546

681-
APILambdaPermission:
682-
Type: AWS::Lambda::Permission
683-
Properties:
684-
FunctionName: !GetAtt AppApiLambdaFunction.Arn
685-
Action: lambda:InvokeFunction
686-
Principal: apigateway.amazonaws.com
687-
SourceArn:
688-
Fn::Join:
689-
- ""
690-
- - "arn:aws:execute-api:"
691-
- !Ref AWS::Region
692-
- ":"
693-
- !Ref AWS::AccountId
694-
- ":"
695-
- !Ref AppApiGateway
696-
- "/*/*/*"
697-
698547
AppFrontendS3Bucket:
699548
Type: AWS::S3::Bucket
700549
Properties:
@@ -718,7 +567,7 @@ Resources:
718567
DomainName: !GetAtt AppFrontendS3Bucket.RegionalDomainName
719568
S3OriginConfig:
720569
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
721-
- Id: ApiGatewayOrigin
570+
- Id: LambdaOrigin
722571
DomainName: !Select [0, !Split ['/', !Select [1, !Split ['https://', !GetAtt AppLambdaUrl.FunctionUrl]]]]
723572
CustomOriginConfig:
724573
HTTPPort: 80
@@ -755,7 +604,7 @@ Resources:
755604
LambdaFunctionARN: !Ref AppFrontendEdgeLambdaVersion
756605
CacheBehaviors:
757606
- PathPattern: "/api/v1/events*"
758-
TargetOriginId: ApiGatewayOrigin
607+
TargetOriginId: LambdaOrigin
759608
ViewerProtocolPolicy: redirect-to-https
760609
AllowedMethods:
761610
- GET
@@ -772,7 +621,7 @@ Resources:
772621
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac
773622
Compress: true
774623
- PathPattern: "/api/v1/organizations"
775-
TargetOriginId: ApiGatewayOrigin
624+
TargetOriginId: LambdaOrigin
776625
ViewerProtocolPolicy: redirect-to-https
777626
AllowedMethods:
778627
- GET
@@ -789,7 +638,7 @@ Resources:
789638
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac
790639
Compress: true
791640
- PathPattern: "/api/documentation*"
792-
TargetOriginId: ApiGatewayOrigin
641+
TargetOriginId: LambdaOrigin
793642
ViewerProtocolPolicy: redirect-to-https
794643
AllowedMethods:
795644
- GET
@@ -806,7 +655,7 @@ Resources:
806655
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac
807656
Compress: true
808657
- PathPattern: "/api/*"
809-
TargetOriginId: ApiGatewayOrigin
658+
TargetOriginId: LambdaOrigin
810659
ViewerProtocolPolicy: redirect-to-https
811660
AllowedMethods:
812661
- GET
@@ -881,7 +730,6 @@ Resources:
881730
Headers:
882731
- x-method-override
883732
- origin
884-
- host
885733
- x-http-method
886734
- x-http-method-override
887735
QueryStringsConfig:
@@ -923,13 +771,15 @@ Resources:
923771
DistributionConfig:
924772
HttpVersion: 'http2and3'
925773
Origins:
926-
- Id: ApiGatewayOrigin
927-
DomainName: !Sub "${AppApiGateway}.execute-api.${AWS::Region}.amazonaws.com"
928-
OriginPath: "/default"
774+
- Id: LambdaOrigin
775+
DomainName: !Select [0, !Split ['/', !Select [1, !Split ['https://', !GetAtt AppLambdaUrl.FunctionUrl]]]]
929776
CustomOriginConfig:
930777
HTTPPort: 80
931778
HTTPSPort: 443
932779
OriginProtocolPolicy: https-only
780+
OriginCustomHeaders:
781+
- HeaderName: X-Origin-Verify
782+
HeaderValue: !Join ['-', ['secret', !Select [4, !Split ['-', !Select [2, !Split ['/', !Ref AWS::StackId]]]]]]
933783
Enabled: true
934784
Aliases:
935785
- !Join
@@ -941,7 +791,7 @@ Resources:
941791
- EnvDomainName
942792
DefaultCacheBehavior:
943793
Compress: true
944-
TargetOriginId: ApiGatewayOrigin
794+
TargetOriginId: LambdaOrigin
945795
ViewerProtocolPolicy: redirect-to-https
946796
AllowedMethods:
947797
- GET
@@ -1069,13 +919,6 @@ Resources:
1069919
- ApiGwConfig
1070920
- !Ref RunEnvironment
1071921
- EnvDomainName
1072-
GWCertArn: !FindInMap
1073-
- ApiGwConfig
1074-
- !Ref RunEnvironment
1075-
- EnvCertificateArn
1076-
GWApiId: !Ref AppApiGateway
1077-
GWHostedZoneId:
1078-
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
1079922
CloudfrontDomain: !GetAtt [AppLinkryCloudfrontDistribution, DomainName]
1080923

1081924
Outputs:

0 commit comments

Comments
 (0)