@@ -576,6 +576,8 @@ Resources:
576576 Type : AWS::S3::Bucket
577577 Properties :
578578 BucketName : !Sub ${S3BucketPrefix}-ui
579+ WebsiteConfiguration :
580+ IndexDocument : index.html
579581
580582 CloudFrontOriginAccessIdentity :
581583 Type : AWS::CloudFront::CloudFrontOriginAccessIdentity
@@ -635,6 +637,9 @@ Resources:
635637 Cookies :
636638 Forward : none
637639 CachePolicyId : 658327ea-f89d-4fab-a63d-7e88639e58f6 # caching-optimized
640+ LambdaFunctionAssociations :
641+ - EventType : origin-request
642+ LambdaFunctionARN : !Ref AppFrontendEdgeLambdaVersion
638643 CacheBehaviors :
639644 - PathPattern : " /api/v1/events*"
640645 TargetOriginId : ApiGatewayOrigin
@@ -675,11 +680,6 @@ Resources:
675680 - EnvCertificateArn
676681 MinimumProtocolVersion : TLSv1.2_2021
677682 SslSupportMethod : sni-only
678- CustomErrorResponses :
679- - ErrorCode : 403
680- ResponseCode : 200
681- ResponsePagePath : /index.html
682- ErrorCachingMinTTL : 0
683683 HttpVersion : http2
684684 PriceClass : PriceClass_100
685685
@@ -721,6 +721,34 @@ Resources:
721721 CookiesConfig :
722722 CookieBehavior : none
723723
724+ AppFrontendEdgeLambda :
725+ Type : AWS::Lambda::Function
726+ DependsOn :
727+ - AppLogGroups
728+ Properties :
729+ FunctionName : !Sub ${ApplicationPrefix}-lambda-edge
730+ Handler : " index.handler"
731+ Role : !GetAtt AppSecurityRoles.Outputs.EdgeFunctionRoleArn
732+ Runtime : nodejs22.x
733+ Code :
734+ ZipFile : |
735+ 'use strict';
736+ exports.handler = async (event) => {
737+ const request = event.Records[0].cf.request;
738+ const uri = request.uri;
739+ if (!uri.startsWith('/api') && !uri.match(/\.\w+$/)) {
740+ request.uri = "/index.html";
741+ }
742+ return request;
743+ };
744+ MemorySize : 128
745+ Timeout : 5
746+
747+ AppFrontendEdgeLambdaVersion :
748+ Type : AWS::Lambda::Version
749+ Properties :
750+ FunctionName : !Ref AppFrontendEdgeLambda
751+
724752Outputs :
725753 DomainName :
726754 Description : Domain name that the UI is hosted at
0 commit comments