Skip to content

Commit

Permalink
feat(release)!: remove unused xarray, xstac, zarr requirements and co…
Browse files Browse the repository at this point in the history
…nfigure cloudfront with OAC (#394)

### Changed/Updated
- [chore(ingest): remove unused xarray, xstac, and zarr requirements
#393](#393)
- [feat!: configure cloudfront with origin access control (proposal)
#376](#376)
  • Loading branch information
botanical authored Jun 27, 2024
2 parents e6d8c51 + a98fe29 commit 19f308e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 20 deletions.
1 change: 1 addition & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ STAC_BROWSER_BUCKET=
STAC_URL=
CERT_ARN=
VEDA_CLOUDFRONT=
VEDA_CLOUDFRONT_OAC=[OPTIONAL, CONFIGURES ORIGIN ACCESS CONTROL, DEFAULTS TO TRUE]
VEDA_CUSTOM_HOST=
3 changes: 0 additions & 3 deletions ingest_api/runtime/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ python-multipart==0.0.7
requests>=2.27.1
s3fs==2023.3.0
stac-pydantic @ git+https://github.com/ividito/stac-pydantic.git@3f4cb381c85749bb4b15d1181179057ec0f51a94
xarray==2023.1.0
xstac==1.1.0
zarr==2.13.6
boto3==1.24.59
aws_xray_sdk>=2.6.0,<3
aws-lambda-powertools>=1.18.0
5 changes: 5 additions & 0 deletions routes/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class vedaRouteSettings(BaseSettings):
description="Boolean if Cloudfront Distribution should be deployed",
)

cloudfront_oac: Optional[bool] = Field(
True,
description="Boolean that configures Cloufront STAC Browser Origin with Origin Access Control",
)

# STAC S3 browser bucket name
stac_browser_bucket: Optional[str] = Field(
None, description="STAC browser S3 bucket name"
Expand Down
91 changes: 74 additions & 17 deletions routes/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,81 @@ def __init__(
else None
)

self.distribution = cf.Distribution(
self,
stack_name,
comment=stack_name,
default_behavior=cf.BehaviorOptions(
origin=origins.HttpOrigin(
origin_bucket.bucket_website_domain_name,
protocol_policy=cf.OriginProtocolPolicy.HTTP_ONLY,
origin_id="stac-browser",
if veda_route_settings.cloudfront_oac:
# create the origin access control resource
cfn_origin_access_control = cf.CfnOriginAccessControl(
self,
"VedaCfnOriginAccessControl",
origin_access_control_config=cf.CfnOriginAccessControl.OriginAccessControlConfigProperty(
name=f"veda-{stage}-oac",
origin_access_control_origin_type="s3",
signing_behavior="always",
signing_protocol="sigv4",
description="Origin Access Control for STAC Browser",
),
cache_policy=cf.CachePolicy.CACHING_DISABLED,
),
certificate=domain_cert,
enable_logging=True,
domain_names=[f"{stage}.{veda_route_settings.domain_hosted_zone_name}"]
if veda_route_settings.domain_hosted_zone_name
else None,
)
)

self.distribution = cf.Distribution(
self,
stack_name,
comment=stack_name,
default_behavior=cf.BehaviorOptions(
origin=origins.S3Origin(
origin_bucket, origin_id="stac-browser"
),
cache_policy=cf.CachePolicy.CACHING_DISABLED,
origin_request_policy=cf.OriginRequestPolicy.CORS_S3_ORIGIN,
response_headers_policy=cf.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS,
viewer_protocol_policy=cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
),
certificate=domain_cert,
default_root_object="index.html",
enable_logging=True,
domain_names=[
f"{stage}.{veda_route_settings.domain_hosted_zone_name}"
]
if veda_route_settings.domain_hosted_zone_name
else None,
)
# associate the created OAC with the distribution
distribution_props = self.distribution.node.default_child
if distribution_props is not None:
distribution_props.add_override(
"Properties.DistributionConfig.Origins.0.S3OriginConfig.OriginAccessIdentity",
"",
)
distribution_props.add_property_override(
"DistributionConfig.Origins.0.OriginAccessControlId",
cfn_origin_access_control.ref,
)

# remove the OAI reference from the distribution
all_distribution_props = self.distribution.node.find_all()
for child in all_distribution_props:
if child.node.id == "S3Origin":
child.node.try_remove_child("Resource")
else:
self.distribution = cf.Distribution(
self,
stack_name,
comment=stack_name,
default_behavior=cf.BehaviorOptions(
origin=origins.HttpOrigin(
origin_bucket.bucket_website_domain_name,
protocol_policy=cf.OriginProtocolPolicy.HTTP_ONLY,
origin_id="stac-browser",
),
cache_policy=cf.CachePolicy.CACHING_DISABLED,
),
certificate=domain_cert,
default_root_object="index.html",
enable_logging=True,
domain_names=[
f"{stage}.{veda_route_settings.domain_hosted_zone_name}"
]
if veda_route_settings.domain_hosted_zone_name
else None,
)

self.distribution.add_behavior(
path_pattern="/api/stac*",
Expand Down

0 comments on commit 19f308e

Please sign in to comment.