-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: include stage subdomain in cloudfront distribution #237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from aws_cdk import aws_certificatemanager as certificatemanager | ||
from aws_cdk import aws_cloudfront as cf | ||
from aws_cdk import aws_cloudfront_origins as origins | ||
from aws_cdk import aws_route53, aws_route53_targets | ||
from aws_cdk import aws_s3 as s3 | ||
from constructs import Construct | ||
|
||
|
@@ -19,6 +20,7 @@ def __init__( | |
self, | ||
scope: Construct, | ||
construct_id: str, | ||
stage: str, | ||
raster_api_id: str, | ||
stac_api_id: str, | ||
region: Optional[str], | ||
|
@@ -53,36 +55,57 @@ def __init__( | |
origin=origins.HttpOrigin( | ||
s3Bucket.bucket_website_domain_name, | ||
protocol_policy=cf.OriginProtocolPolicy.HTTP_ONLY, | ||
origin_id="stac-browser", | ||
), | ||
cache_policy=cf.CachePolicy.CACHING_DISABLED, | ||
), | ||
certificate=domain_cert, | ||
domain_names=[veda_route_settings.domain_hosted_zone_name] | ||
domain_names=[f"{stage}.{veda_route_settings.domain_hosted_zone_name}"] | ||
if veda_route_settings.domain_hosted_zone_name | ||
else None, | ||
additional_behaviors={ | ||
"/api/stac*": cf.BehaviorOptions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed this additional behaviors in the last PR, maybe we can drop a TODO here to make this configurable in the condition that a path prefex is used like |
||
origin=origins.HttpOrigin( | ||
f"{stac_api_id}.execute-api.{region}.amazonaws.com" | ||
f"{stac_api_id}.execute-api.{region}.amazonaws.com", | ||
origin_id="stac-api", | ||
), | ||
cache_policy=cf.CachePolicy.CACHING_DISABLED, | ||
allowed_methods=cf.AllowedMethods.ALLOW_ALL, | ||
), | ||
"/api/raster*": cf.BehaviorOptions( | ||
origin=origins.HttpOrigin( | ||
f"{raster_api_id}.execute-api.{region}.amazonaws.com" | ||
f"{raster_api_id}.execute-api.{region}.amazonaws.com", | ||
origin_id="raster-api", | ||
), | ||
cache_policy=cf.CachePolicy.CACHING_DISABLED, | ||
allowed_methods=cf.AllowedMethods.ALLOW_ALL, | ||
), | ||
"/api/ingest*": cf.BehaviorOptions( | ||
origin=origins.HttpOrigin( | ||
urlparse(veda_route_settings.ingest_url).hostname | ||
urlparse(veda_route_settings.ingest_url).hostname, | ||
origin_id="ingest-api", | ||
), | ||
cache_policy=cf.CachePolicy.CACHING_DISABLED, | ||
allowed_methods=cf.AllowedMethods.ALLOW_ALL, | ||
), | ||
}, | ||
) | ||
|
||
hosted_zone = aws_route53.HostedZone.from_hosted_zone_attributes( | ||
self, | ||
"hosted-zone", | ||
hosted_zone_id=veda_route_settings.domain_hosted_zone_id, | ||
zone_name=veda_route_settings.domain_hosted_zone_name, | ||
) | ||
|
||
aws_route53.ARecord( | ||
self, | ||
"cloudfront-dns-record", | ||
zone=hosted_zone, | ||
target=aws_route53.RecordTarget.from_alias( | ||
aws_route53_targets.CloudFrontTarget(self.distribution) | ||
), | ||
record_name=stage, | ||
) | ||
|
||
CfnOutput(self, "Endpoint", value=self.distribution.domain_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment for future work: maybe we can add a method in the api config files to add a stage subdomain for all non-prod stages? We don't need that now so it's just something to think about.