-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3_bucket.py
32 lines (27 loc) · 867 Bytes
/
s3_bucket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from aws_cdk import (
aws_s3 as s3,
RemovalPolicy,
Duration,
)
from constructs import Construct
class S3Bucket(Construct):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Create the S3 bucket
self.bucket = s3.Bucket(
self,
f"BucketResource",
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
block_public_access=s3.BlockPublicAccess(
block_public_acls=True,
block_public_policy=True,
restrict_public_buckets=True,
ignore_public_acls=True,
),
)
# Add bucket lifecycle rule
self.bucket.add_lifecycle_rule(
noncurrent_version_expiration=Duration.days(60),
enabled=True,
)