Skip to content

Commit fcaf5ff

Browse files
committed
fix the ical domain by using a seperate distribution for API routes
1 parent 9afe72f commit fcaf5ff

File tree

3 files changed

+93
-19
lines changed

3 files changed

+93
-19
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ deploy_dev: check_account_dev build
8080
invalidate_cloudfront:
8181
@echo "Creating CloudFront invalidation..."
8282
$(eval DISTRIBUTION_ID := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontDistributionId'].OutputValue" --output text))
83+
$(eval DISTRIBUTION_ID_2 := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontSecondaryDistributionId'].OutputValue" --output text))
8384
$(eval INVALIDATION_ID := $(shell aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID) --paths "/*" --query 'Invalidation.Id' --output text --no-cli-page))
85+
$(eval INVALIDATION_ID_2 := $(shell aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID_2) --paths "/*" --query 'Invalidation.Id' --output text --no-cli-page))
8486
@echo "Waiting on job $(INVALIDATION_ID)..."
8587
aws cloudfront wait invalidation-completed --distribution-id $(DISTRIBUTION_ID) --id $(INVALIDATION_ID)
88+
@echo "Waiting on job $(INVALIDATION_ID_2)..."
89+
aws cloudfront wait invalidation-completed --distribution-id $(DISTRIBUTION_ID_2) --id $(INVALIDATION_ID_2)
8690
@echo "CloudFront invalidation completed!"
8791

8892
install:

cloudformation/main.yml

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Resources:
123123
GWApiId: !Ref AppApiGateway
124124
GWHostedZoneId:
125125
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
126-
CloudfrontDomain: !GetAtt [AppFrontendCloudfrontDistribution, DomainName]
126+
CloudfrontDomain: !GetAtt [AppIcalCloudfrontDistribution, DomainName]
127127

128128
LinkryDomainProxy:
129129
Type: AWS::Serverless::Application
@@ -143,7 +143,7 @@ Resources:
143143
GWApiId: !Ref AppApiGateway
144144
GWHostedZoneId:
145145
!FindInMap [ApiGwConfig, !Ref RunEnvironment, HostedZoneId]
146-
CloudfrontDomain: !GetAtt [AppFrontendCloudfrontDistribution, DomainName]
146+
CloudfrontDomain: !GetAtt [AppIcalCloudfrontDistribution, DomainName]
147147

148148
CoreUrlProd:
149149
Type: AWS::Serverless::Application
@@ -626,20 +626,6 @@ Resources:
626626
- ApiGwConfig
627627
- !Ref RunEnvironment
628628
- UiDomainName
629-
- !Join
630-
- ""
631-
- - "go."
632-
- !FindInMap
633-
- ApiGwConfig
634-
- !Ref RunEnvironment
635-
- EnvDomainName
636-
- !Join
637-
- ""
638-
- - "ical."
639-
- !FindInMap
640-
- ApiGwConfig
641-
- !Ref RunEnvironment
642-
- EnvDomainName
643629

644630
DefaultCacheBehavior:
645631
TargetOriginId: S3WebsiteOrigin
@@ -767,23 +753,95 @@ Resources:
767753
Properties:
768754
FunctionName: !Ref AppFrontendEdgeLambda
769755

756+
AppIcalCloudfrontDistribution:
757+
Type: AWS::CloudFront::Distribution
758+
Properties:
759+
DistributionConfig:
760+
Origins:
761+
- Id: ApiGatewayOrigin
762+
DomainName: !Sub "${AppApiGateway}.execute-api.${AWS::Region}.amazonaws.com"
763+
OriginPath: "/default"
764+
CustomOriginConfig:
765+
HTTPPort: 80
766+
HTTPSPort: 443
767+
OriginProtocolPolicy: https-only
768+
Enabled: true
769+
Aliases:
770+
- !Join
771+
- ""
772+
- - "go."
773+
- !FindInMap
774+
- ApiGwConfig
775+
- !Ref RunEnvironment
776+
- EnvDomainName
777+
- !Join
778+
- ""
779+
- - "ical."
780+
- !FindInMap
781+
- ApiGwConfig
782+
- !Ref RunEnvironment
783+
- EnvDomainName
784+
DefaultCacheBehavior:
785+
TargetOriginId: ApiGatewayOrigin
786+
ViewerProtocolPolicy: redirect-to-https
787+
AllowedMethods:
788+
- GET
789+
- HEAD
790+
- OPTIONS
791+
- PUT
792+
- POST
793+
- DELETE
794+
- PATCH
795+
CachedMethods:
796+
- GET
797+
- HEAD
798+
ForwardedValues:
799+
QueryString: false
800+
Cookies:
801+
Forward: none
802+
CachePolicyId: !Ref CloudfrontCachePolicy
803+
OriginRequestPolicyId: 216adef6-5c7f-47e4-b989-5492eafa07d3
804+
ViewerCertificate:
805+
AcmCertificateArn: !FindInMap
806+
- ApiGwConfig
807+
- !Ref RunEnvironment
808+
- EnvCertificateArn
809+
MinimumProtocolVersion: TLSv1.2_2021
810+
SslSupportMethod: sni-only
811+
HttpVersion: http2
812+
PriceClass: PriceClass_100
813+
814+
770815
Outputs:
771816
DomainName:
772817
Description: Domain name that the UI is hosted at
773818
Value: !FindInMap
774819
- ApiGwConfig
775820
- !Ref RunEnvironment
776821
- UiDomainName
822+
777823
CloudfrontCnameTarget:
778824
Description: CNAME record target to create for the domain name above (create the CNAME manually)
779825
Value:
780826
Fn::GetAtt:
781827
- AppFrontendCloudfrontDistribution
782828
- DomainName
829+
830+
CloudfrontSecondaryCnameTarget:
831+
Description: CNAME record target to create for the secondary domain names (create the CNAME manually)
832+
Value:
833+
Fn::GetAtt:
834+
- AppIcalCloudfrontDistribution
835+
- DomainName
836+
783837
CloudfrontDistributionId:
784838
Description: Cloudfront Distribution ID
785839
Value: !GetAtt AppFrontendCloudfrontDistribution.Id
786840

841+
CloudfrontSecondaryDistributionId:
842+
Description: Cloudfront Distribution ID
843+
Value: !GetAtt AppIcalCloudfrontDistribution.Id
844+
787845
SalesEmailQueueArn:
788846
Description: Sales Email Queue Arn
789847
Value: !GetAtt AppSQSQueues.Outputs.SalesEmailQueueArn

tests/live/ical.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { OrganizationList } from "../../src/common/orgs.js";
44
import ical from "node-ical";
55
const baseEndpoint = `https://core.aws.qa.acmuiuc.org`;
66

7-
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7+
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
88

9-
const fetchWithRateLimit = async (url) => {
9+
const fetchWithRateLimit = async (url: string) => {
1010
const response = await fetch(url);
1111
expect(response.status).toBe(200);
1212

@@ -27,7 +27,7 @@ const fetchWithRateLimit = async (url) => {
2727
return response;
2828
};
2929

30-
test("Get calendars with rate limit handling", { timeout: 30000 }, async () => {
30+
test("Get calendars with rate limit handling", { timeout: 45000 }, async () => {
3131
for (const org of OrganizationList) {
3232
const response = await fetchWithRateLimit(
3333
`${baseEndpoint}/api/v1/ical/${org}`,
@@ -40,3 +40,15 @@ test("Get calendars with rate limit handling", { timeout: 30000 }, async () => {
4040
expect(calendar["vcalendar"]["type"]).toEqual("VCALENDAR");
4141
}
4242
});
43+
44+
test("Check that the ical base works", { timeout: 45000 }, async () => {
45+
const response = await fetchWithRateLimit(
46+
`${baseEndpoint.replace("core", "ical")}/ACM`,
47+
);
48+
expect(response.status).toBe(200);
49+
expect(response.headers.get("Content-Disposition")).toEqual(
50+
'attachment; filename="calendar.ics"',
51+
);
52+
const calendar = ical.sync.parseICS(await response.text());
53+
expect(calendar["vcalendar"]["type"]).toEqual("VCALENDAR");
54+
});

0 commit comments

Comments
 (0)