@@ -42,24 +42,81 @@ def __init__(
42
42
else None
43
43
)
44
44
45
- self .distribution = cf .Distribution (
46
- self ,
47
- stack_name ,
48
- comment = stack_name ,
49
- default_behavior = cf .BehaviorOptions (
50
- origin = origins .HttpOrigin (
51
- origin_bucket .bucket_website_domain_name ,
52
- protocol_policy = cf .OriginProtocolPolicy .HTTP_ONLY ,
53
- origin_id = "stac-browser" ,
45
+ if veda_route_settings .cloudfront_oac :
46
+ # create the origin access control resource
47
+ cfn_origin_access_control = cf .CfnOriginAccessControl (
48
+ self ,
49
+ "VedaCfnOriginAccessControl" ,
50
+ origin_access_control_config = cf .CfnOriginAccessControl .OriginAccessControlConfigProperty (
51
+ name = f"veda-{ stage } -oac" ,
52
+ origin_access_control_origin_type = "s3" ,
53
+ signing_behavior = "always" ,
54
+ signing_protocol = "sigv4" ,
55
+ description = "Origin Access Control for STAC Browser" ,
54
56
),
55
- cache_policy = cf .CachePolicy .CACHING_DISABLED ,
56
- ),
57
- certificate = domain_cert ,
58
- enable_logging = True ,
59
- domain_names = [f"{ stage } .{ veda_route_settings .domain_hosted_zone_name } " ]
60
- if veda_route_settings .domain_hosted_zone_name
61
- else None ,
62
- )
57
+ )
58
+
59
+ self .distribution = cf .Distribution (
60
+ self ,
61
+ stack_name ,
62
+ comment = stack_name ,
63
+ default_behavior = cf .BehaviorOptions (
64
+ origin = origins .S3Origin (
65
+ origin_bucket , origin_id = "stac-browser"
66
+ ),
67
+ cache_policy = cf .CachePolicy .CACHING_DISABLED ,
68
+ origin_request_policy = cf .OriginRequestPolicy .CORS_S3_ORIGIN ,
69
+ response_headers_policy = cf .ResponseHeadersPolicy .CORS_ALLOW_ALL_ORIGINS ,
70
+ viewer_protocol_policy = cf .ViewerProtocolPolicy .REDIRECT_TO_HTTPS ,
71
+ ),
72
+ certificate = domain_cert ,
73
+ default_root_object = "index.html" ,
74
+ enable_logging = True ,
75
+ domain_names = [
76
+ f"{ stage } .{ veda_route_settings .domain_hosted_zone_name } "
77
+ ]
78
+ if veda_route_settings .domain_hosted_zone_name
79
+ else None ,
80
+ )
81
+ # associate the created OAC with the distribution
82
+ distribution_props = self .distribution .node .default_child
83
+ if distribution_props is not None :
84
+ distribution_props .add_override (
85
+ "Properties.DistributionConfig.Origins.0.S3OriginConfig.OriginAccessIdentity" ,
86
+ "" ,
87
+ )
88
+ distribution_props .add_property_override (
89
+ "DistributionConfig.Origins.0.OriginAccessControlId" ,
90
+ cfn_origin_access_control .ref ,
91
+ )
92
+
93
+ # remove the OAI reference from the distribution
94
+ all_distribution_props = self .distribution .node .find_all ()
95
+ for child in all_distribution_props :
96
+ if child .node .id == "S3Origin" :
97
+ child .node .try_remove_child ("Resource" )
98
+ else :
99
+ self .distribution = cf .Distribution (
100
+ self ,
101
+ stack_name ,
102
+ comment = stack_name ,
103
+ default_behavior = cf .BehaviorOptions (
104
+ origin = origins .HttpOrigin (
105
+ origin_bucket .bucket_website_domain_name ,
106
+ protocol_policy = cf .OriginProtocolPolicy .HTTP_ONLY ,
107
+ origin_id = "stac-browser" ,
108
+ ),
109
+ cache_policy = cf .CachePolicy .CACHING_DISABLED ,
110
+ ),
111
+ certificate = domain_cert ,
112
+ default_root_object = "index.html" ,
113
+ enable_logging = True ,
114
+ domain_names = [
115
+ f"{ stage } .{ veda_route_settings .domain_hosted_zone_name } "
116
+ ]
117
+ if veda_route_settings .domain_hosted_zone_name
118
+ else None ,
119
+ )
63
120
64
121
self .distribution .add_behavior (
65
122
path_pattern = "/api/stac*" ,
0 commit comments