aws-cdk-constructs 2.26.0__tar.gz → 2.26.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/PKG-INFO +1 -1
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/__init__.py +1 -1
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/bucket/bucket.py +129 -18
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/PKG-INFO +1 -1
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/LICENSE.txt +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/MANIFEST.in +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/README.md +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/api/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/api/api.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/bucket/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/_types/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/_types/document.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/_types/graph.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/_types/relational.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/database.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/types.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/cluster.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/fargate_validator.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/microservice.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/efs/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/efs/volume.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/alb.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/nlb.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/microservice/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/microservice/base_user_data.sh +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/microservice/manage_connection_to_nlb_instance_security_group_ingress/lambda_function.js +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/microservice/microservice.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/security_group/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/security_group/security_group.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/service_user_for_iac/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/service_user_for_iac/service_user_for_iac.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/service_user_for_static_assets/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/service_user_for_static_assets/service_user_for_static_assets.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/utils.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/windows_server/__init__.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/windows_server/user_data.ps1 +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/windows_server/windows_server.py +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/SOURCES.txt +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/dependency_links.txt +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/requires.txt +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/top_level.txt +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/setup.cfg +0 -0
- {aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/setup.py +0 -0
|
@@ -103,6 +103,7 @@ class Bucket(Construct):
|
|
|
103
103
|
|
|
104
104
|
cdn_ssl_certificate_arn (str): If "will_implement_cdn" is "True" and you want to enable HTTPS for your CloudFront distribution, specify the SSL certificate ARN to use. NB: this certificate must be in North Virginia
|
|
105
105
|
|
|
106
|
+
bucket_policy_statements: List[_iam.PolicyStatement]: List of policy statements to be added to the Bucket policy. Default: []
|
|
106
107
|
"""
|
|
107
108
|
|
|
108
109
|
@property
|
|
@@ -160,8 +161,9 @@ class Bucket(Construct):
|
|
|
160
161
|
encryption_allowed_principals_arns: Union[str, List[str]] = None,
|
|
161
162
|
enforce_ssl: bool = False,
|
|
162
163
|
will_implement_cdn: str = 'false',
|
|
163
|
-
cdn_domain_names: [str] = [],
|
|
164
|
+
cdn_domain_names: List[str] = [],
|
|
164
165
|
cdn_ssl_certificate_arn: str = None,
|
|
166
|
+
bucket_policy_statements: List[_iam.PolicyStatement] = [],
|
|
165
167
|
**kwargs,
|
|
166
168
|
) -> aws_cdk.aws_s3.Bucket:
|
|
167
169
|
"""Create an S3 bucket
|
|
@@ -198,6 +200,8 @@ class Bucket(Construct):
|
|
|
198
200
|
|
|
199
201
|
cdn_ssl_certificate_arn (str): If "will_implement_cdn" is "True" and you want to enable HTTPS for your CloudFront distribution, specify the SSL certificate ARN to use. NB: this certificate must be in North Virginia
|
|
200
202
|
|
|
203
|
+
bucket_policy_statements: List[_iam.PolicyStatement]: List of policy statements to be added to the Bucket policy. Default: []
|
|
204
|
+
|
|
201
205
|
Returns:
|
|
202
206
|
aws_s3.Bucket: the S3 bucket
|
|
203
207
|
"""
|
|
@@ -299,30 +303,131 @@ class Bucket(Construct):
|
|
|
299
303
|
)
|
|
300
304
|
# Create CloudFront distribution
|
|
301
305
|
if create_cloudfront_distribution:
|
|
306
|
+
distribution_id = f'distribution_{bucket_name}'
|
|
302
307
|
self._cloudfront_distribution = _cloudfront.Distribution(
|
|
303
308
|
self,
|
|
304
|
-
|
|
309
|
+
distribution_id,
|
|
305
310
|
default_behavior=_cloudfront.BehaviorOptions(
|
|
306
311
|
origin=_cloudfront_origins.S3Origin(s3_bucket),
|
|
307
312
|
compress=True,
|
|
308
313
|
viewer_protocol_policy=_cloudfront.ViewerProtocolPolicy.HTTPS_ONLY,
|
|
309
314
|
allowed_methods=_cloudfront.AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
|
|
310
315
|
cache_policy=_cloudfront.CachePolicy.CACHING_DISABLED,
|
|
311
|
-
origin_request_policy=_cloudfront.OriginRequestPolicy.
|
|
316
|
+
origin_request_policy=_cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
312
317
|
),
|
|
313
318
|
certificate=_certificate.Certificate.from_certificate_arn(
|
|
314
319
|
self,
|
|
315
320
|
'https_certificate_cdn',
|
|
316
|
-
certificate_arn=
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
+
certificate_arn=(
|
|
322
|
+
cdn_ssl_certificate_arn
|
|
323
|
+
if cdn_ssl_certificate_arn
|
|
324
|
+
else self.aws_account[
|
|
325
|
+
'ssl_certificate_star_fao_org_arn_north_virginia'
|
|
326
|
+
]
|
|
327
|
+
),
|
|
321
328
|
),
|
|
322
329
|
price_class=_cloudfront.PriceClass.PRICE_CLASS_100,
|
|
323
330
|
domain_names=cdn_domain_names,
|
|
324
331
|
)
|
|
325
332
|
|
|
333
|
+
self._origin_access_control = _cloudfront.CfnOriginAccessControl(
|
|
334
|
+
self,
|
|
335
|
+
f'oac_{bucket_name}',
|
|
336
|
+
origin_access_control_config=_cloudfront.CfnOriginAccessControl.OriginAccessControlConfigProperty(
|
|
337
|
+
name=f'oac_{bucket_name}',
|
|
338
|
+
origin_access_control_origin_type='s3',
|
|
339
|
+
signing_behavior='always',
|
|
340
|
+
signing_protocol='sigv4',
|
|
341
|
+
),
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
cloudfront_distribution_arn = (
|
|
345
|
+
f'arn:aws:cloudfront::'
|
|
346
|
+
+ self.aws_account['id']
|
|
347
|
+
+ f':distribution/{self._cloudfront_distribution.distribution_id}'
|
|
348
|
+
)
|
|
349
|
+
bucket_statement = _iam.PolicyStatement(
|
|
350
|
+
principals=[_iam.ServicePrincipal('cloudfront.amazonaws.com')],
|
|
351
|
+
actions=['s3:GetObject'],
|
|
352
|
+
resources=[f'{s3_bucket.bucket_arn}/*'],
|
|
353
|
+
conditions={
|
|
354
|
+
'StringEquals': {
|
|
355
|
+
'aws:sourceArn': cloudfront_distribution_arn
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
s3_bucket.add_to_resource_policy(bucket_statement)
|
|
361
|
+
|
|
362
|
+
# Add custom policy statements to bucket policy
|
|
363
|
+
for statement in bucket_policy_statements:
|
|
364
|
+
s3_bucket.add_to_resource_policy(statement)
|
|
365
|
+
|
|
366
|
+
## clean-up the OAI reference and associate the OAC with the cloudfront distribution
|
|
367
|
+
# query the site bucket policy as a document
|
|
368
|
+
bucket_policy = s3_bucket.policy
|
|
369
|
+
bucket_policy_document = bucket_policy.document
|
|
370
|
+
|
|
371
|
+
# remove the CloudFront Origin Access Identity permission from the bucket policy
|
|
372
|
+
if isinstance(bucket_policy_document, _iam.PolicyDocument):
|
|
373
|
+
bucket_policy_document_json = bucket_policy_document.to_json()
|
|
374
|
+
# create an updated policy without the OAI reference
|
|
375
|
+
bucket_policy_updated_json = {
|
|
376
|
+
'Version': '2012-10-17',
|
|
377
|
+
'Statement': [],
|
|
378
|
+
}
|
|
379
|
+
for statement in bucket_policy_document_json['Statement']:
|
|
380
|
+
if 'CanonicalUser' not in statement['Principal']:
|
|
381
|
+
bucket_policy_updated_json['Statement'].append(
|
|
382
|
+
statement
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
# apply the updated bucket policy to the bucket
|
|
386
|
+
bucket_policy_override = s3_bucket.node.find_child(
|
|
387
|
+
'Policy'
|
|
388
|
+
).node.default_child
|
|
389
|
+
bucket_policy_override.add_override(
|
|
390
|
+
'Properties.PolicyDocument', bucket_policy_updated_json
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
# remove the created OAI reference (S3 Origin property) for the distribution
|
|
394
|
+
all_distribution_props = (
|
|
395
|
+
self._cloudfront_distribution.node.find_all()
|
|
396
|
+
)
|
|
397
|
+
for child in all_distribution_props:
|
|
398
|
+
if child.node.id == 'S3Origin':
|
|
399
|
+
child.node.try_remove_child('Resource')
|
|
400
|
+
|
|
401
|
+
# associate the created OAC with the distribution
|
|
402
|
+
distribution_props = (
|
|
403
|
+
self._cloudfront_distribution.node.default_child
|
|
404
|
+
)
|
|
405
|
+
distribution_props.add_override(
|
|
406
|
+
'Properties.DistributionConfig.Origins.0.S3OriginConfig.OriginAccessIdentity',
|
|
407
|
+
'',
|
|
408
|
+
)
|
|
409
|
+
distribution_props.add_property_override(
|
|
410
|
+
'DistributionConfig.Origins.0.OriginAccessControlId',
|
|
411
|
+
self._origin_access_control.ref,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
# Assign Origin Access Control
|
|
415
|
+
# indexes = ["0"]
|
|
416
|
+
# for index in indexes:
|
|
417
|
+
# self._cloudfront_distribution.node.find_child(
|
|
418
|
+
# "Resource"
|
|
419
|
+
# ).add_property_override(
|
|
420
|
+
# f"DistributionConfig.Origins.{index}.OriginAccessControlId",
|
|
421
|
+
# self._origin_access_control.get_att("Id"),
|
|
422
|
+
# )
|
|
423
|
+
|
|
424
|
+
# self._cloudfront_distribution.node.find_child(
|
|
425
|
+
# "Resource"
|
|
426
|
+
# ).add_property_override(
|
|
427
|
+
# f"DistributionConfig.Origins.{index}.S3OriginConfig.OriginAccessIdentity",
|
|
428
|
+
# {},
|
|
429
|
+
# )
|
|
430
|
+
|
|
326
431
|
return s3_bucket
|
|
327
432
|
|
|
328
433
|
def __init__(
|
|
@@ -349,6 +454,7 @@ class Bucket(Construct):
|
|
|
349
454
|
will_implement_cdn: str = 'false',
|
|
350
455
|
cdn_domain_names: [str] = [],
|
|
351
456
|
cdn_ssl_certificate_arn: str = None,
|
|
457
|
+
bucket_policy_statements: List[_iam.PolicyStatement] = [],
|
|
352
458
|
**kwargs,
|
|
353
459
|
) -> None:
|
|
354
460
|
super().__init__(scope, id, **kwargs)
|
|
@@ -459,17 +565,21 @@ class Bucket(Construct):
|
|
|
459
565
|
website_index_document=bucket_website_index_document,
|
|
460
566
|
website_error_document=bucket_website_error_document,
|
|
461
567
|
removal_policy=removal_policy,
|
|
462
|
-
access_control=
|
|
463
|
-
|
|
464
|
-
|
|
568
|
+
access_control=(
|
|
569
|
+
_s3.BucketAccessControl.PRIVATE
|
|
570
|
+
if not public_read_access
|
|
571
|
+
else None
|
|
572
|
+
),
|
|
465
573
|
# https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html,
|
|
466
|
-
block_public_access=
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
574
|
+
block_public_access=(
|
|
575
|
+
_s3.BlockPublicAccess.BLOCK_ALL
|
|
576
|
+
if not public_read_access
|
|
577
|
+
else _s3.BlockPublicAccess(
|
|
578
|
+
block_public_acls=False,
|
|
579
|
+
block_public_policy=False,
|
|
580
|
+
ignore_public_acls=False,
|
|
581
|
+
restrict_public_buckets=False,
|
|
582
|
+
)
|
|
473
583
|
),
|
|
474
584
|
versioned=versioned,
|
|
475
585
|
is_encrypted=is_encrypted,
|
|
@@ -478,6 +588,7 @@ class Bucket(Construct):
|
|
|
478
588
|
will_implement_cdn=will_implement_cdn,
|
|
479
589
|
cdn_domain_names=cdn_domain_names,
|
|
480
590
|
cdn_ssl_certificate_arn=cdn_ssl_certificate_arn,
|
|
591
|
+
bucket_policy_statements=bucket_policy_statements,
|
|
481
592
|
)
|
|
482
593
|
|
|
483
594
|
if bucket_is_privately_accessed_from_vpc_over_http:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/bucket/__init__.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/_types/graph.py
RENAMED
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/database.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/database/types.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/fargate_validator.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/ecs/microservice.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/__init__.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/alb.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/load_balancer/nlb.py
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs/microservice/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/requires.txt
RENAMED
|
File without changes
|
{aws_cdk_constructs-2.26.0 → aws_cdk_constructs-2.26.2}/aws_cdk_constructs.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|