@@ -87,6 +87,7 @@ Resources:
87
87
LambdaFunctionName : !Sub ${ApplicationPrefix}-lambda
88
88
SesEmailDomain : !FindInMap [General, !Ref RunEnvironment, SesDomain]
89
89
SqsQueueArn : !GetAtt AppSQSQueues.Outputs.MainQueueArn
90
+ LinkryKvArn : !GetAtt LinkryRecordsCloudfrontStore.Arn
90
91
91
92
AppLogGroups :
92
93
Type : AWS::Serverless::Application
@@ -125,26 +126,6 @@ Resources:
125
126
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
126
127
CloudfrontDomain : !GetAtt [AppIcalCloudfrontDistribution, DomainName]
127
128
128
- LinkryDomainProxy :
129
- Type : AWS::Serverless::Application
130
- Properties :
131
- Location : ./custom-domain.yml
132
- Parameters :
133
- RunEnvironment : !Ref RunEnvironment
134
- RecordName : go
135
- GWBaseDomainName : !FindInMap
136
- - ApiGwConfig
137
- - !Ref RunEnvironment
138
- - EnvDomainName
139
- GWCertArn : !FindInMap
140
- - ApiGwConfig
141
- - !Ref RunEnvironment
142
- - EnvCertificateArn
143
- GWApiId : !Ref AppApiGateway
144
- GWHostedZoneId :
145
- !FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
146
- CloudfrontDomain : !GetAtt [AppIcalCloudfrontDistribution, DomainName]
147
-
148
129
CoreUrlProd :
149
130
Type : AWS::Serverless::Application
150
131
Properties :
@@ -184,6 +165,8 @@ Resources:
184
165
Variables :
185
166
RunEnvironment : !Ref RunEnvironment
186
167
EntraRoleArn : !GetAtt AppSecurityRoles.Outputs.EntraFunctionRoleArn
168
+ LinkryKvArn : !GetAtt LinkryRecordsCloudfrontStore.Arn
169
+ AWS_CRT_NODEJS_BINARY_RELATIVE_PATH : node_modules/aws-crt/dist/bin/linux-arm64-glibc/aws-crt-nodejs.node
187
170
VpcConfig :
188
171
Ipv6AllowedForDualStack : !If [ShouldAttachVpc, True, !Ref AWS::NoValue]
189
172
SecurityGroupIds :
@@ -483,6 +466,34 @@ Resources:
483
466
Projection :
484
467
ProjectionType : " ALL"
485
468
469
+ LinkryRecordsTable :
470
+ Type : " AWS::DynamoDB::Table"
471
+ Properties :
472
+ BillingMode : " PAY_PER_REQUEST"
473
+ TableName : " infra-core-api-linkry"
474
+ DeletionProtectionEnabled : !If [IsProd, true, false] # TODO: remove this
475
+ PointInTimeRecoverySpecification :
476
+ PointInTimeRecoveryEnabled : !If [IsProd, true, false]
477
+ AttributeDefinitions :
478
+ - AttributeName : " slug"
479
+ AttributeType : " S"
480
+ - AttributeName : " access"
481
+ AttributeType : " S"
482
+ KeySchema :
483
+ - AttributeName : " slug"
484
+ KeyType : " HASH"
485
+ - AttributeName : " access"
486
+ KeyType : " RANGE"
487
+ GlobalSecondaryIndexes :
488
+ - IndexName : " AccessIndex"
489
+ KeySchema :
490
+ - AttributeName : " access"
491
+ KeyType : " HASH"
492
+ - AttributeName : " slug"
493
+ KeyType : " RANGE"
494
+ Projection :
495
+ ProjectionType : " ALL"
496
+
486
497
CacheRecordsTable :
487
498
Type : " AWS::DynamoDB::Table"
488
499
DeletionPolicy : " Retain"
@@ -831,13 +842,6 @@ Resources:
831
842
OriginProtocolPolicy : https-only
832
843
Enabled : true
833
844
Aliases :
834
- - !Join
835
- - " "
836
- - - "go."
837
- - !FindInMap
838
- - ApiGwConfig
839
- - !Ref RunEnvironment
840
- - EnvDomainName
841
845
- !Join
842
846
- " "
843
847
- - "ical."
@@ -875,6 +879,105 @@ Resources:
875
879
HttpVersion : http2
876
880
PriceClass : PriceClass_100
877
881
882
+ LinkryRecordsCloudfrontStore :
883
+ Type : AWS::CloudFront::KeyValueStore
884
+ Properties :
885
+ Name : infra-core-api-cloudfront-linkry-kv
886
+
887
+ LinkryRecordsCloudfrontFunction :
888
+ Type : ' AWS::CloudFront::Function'
889
+ Properties :
890
+ Name : infra-core-api-cloudfront-linkry-redir
891
+ FunctionConfig :
892
+ Comment : ' Linkry Redirect Cloudfront Function'
893
+ Runtime : ' cloudfront-js-2.0'
894
+ KeyValueStoreAssociations :
895
+ - KeyValueStoreARN : !Sub '${LinkryRecordsCloudfrontStore.Arn}'
896
+ FunctionCode : !Sub |
897
+ import cf from 'cloudfront';
898
+ const kvsId = '${LinkryRecordsCloudfrontStore.Id}';
899
+ const kvs = cf.kvs(kvsId);
900
+
901
+ async function handler(event) {
902
+ const request = event.request;
903
+ const path = request.uri.replace(/^\/+/, '');
904
+ let redirectUrl = "https://acm.illinois.edu/404";
905
+ try {
906
+ const value = await kvs.get(path);
907
+ if (value) {
908
+ redirectUrl = value;
909
+ }
910
+ } catch (err) {
911
+ console.log('KVS key lookup failed');
912
+ }
913
+ var response = {
914
+ statusCode: 302,
915
+ statusDescription: 'Found',
916
+ headers: {
917
+ 'location': { value: redirectUrl }
918
+ }
919
+ };
920
+ return response;
921
+ }
922
+ AutoPublish : true
923
+
924
+ AppLinkryCloudfrontDistribution :
925
+ Type : AWS::CloudFront::Distribution
926
+ Properties :
927
+ DistributionConfig :
928
+ Enabled : true
929
+ DefaultCacheBehavior :
930
+ ViewerProtocolPolicy : redirect-to-https
931
+ TargetOriginId : dummyOrigin
932
+ ForwardedValues :
933
+ QueryString : false
934
+ Cookies :
935
+ Forward : none
936
+ FunctionAssociations :
937
+ - EventType : viewer-request
938
+ FunctionARN : !GetAtt LinkryRecordsCloudfrontFunction.FunctionARN
939
+ Origins :
940
+ - Id : dummyOrigin
941
+ DomainName : example.com
942
+ CustomOriginConfig :
943
+ OriginProtocolPolicy : https-only
944
+ Aliases :
945
+ - !Join
946
+ - " "
947
+ - - "go."
948
+ - !FindInMap
949
+ - ApiGwConfig
950
+ - !Ref RunEnvironment
951
+ - EnvDomainName
952
+ ViewerCertificate :
953
+ AcmCertificateArn : !FindInMap
954
+ - ApiGwConfig
955
+ - !Ref RunEnvironment
956
+ - EnvCertificateArn
957
+ MinimumProtocolVersion : TLSv1.2_2021
958
+ SslSupportMethod : sni-only
959
+ HttpVersion : http2
960
+ PriceClass : PriceClass_100
961
+
962
+ LinkryDomainProxy :
963
+ Type : AWS::Serverless::Application
964
+ Properties :
965
+ Location : ./custom-domain.yml
966
+ Parameters :
967
+ RunEnvironment : !Ref RunEnvironment
968
+ RecordName : go
969
+ GWBaseDomainName : !FindInMap
970
+ - ApiGwConfig
971
+ - !Ref RunEnvironment
972
+ - EnvDomainName
973
+ GWCertArn : !FindInMap
974
+ - ApiGwConfig
975
+ - !Ref RunEnvironment
976
+ - EnvCertificateArn
977
+ GWApiId : !Ref AppApiGateway
978
+ GWHostedZoneId :
979
+ !FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
980
+ CloudfrontDomain : !GetAtt [AppLinkryCloudfrontDistribution, DomainName]
878
981
879
982
Outputs :
880
983
DomainName :
@@ -902,7 +1005,7 @@ Outputs:
902
1005
Description : Cloudfront Distribution ID
903
1006
Value : !GetAtt AppFrontendCloudfrontDistribution.Id
904
1007
905
- CloudfrontSecondaryDistributionId :
1008
+ CloudfrontIcalDistributionId :
906
1009
Description : Cloudfront Distribution ID
907
1010
Value : !GetAtt AppIcalCloudfrontDistribution.Id
908
1011
0 commit comments