File size: 1,756 Bytes
d8ad0fd | 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from pathlib import Path
from aws_cdk import CfnOutput, Duration, RemovalPolicy
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_s3_deployment as s3deploy
from tests.e2e.utils.infrastructure import BaseInfrastructure
class StreamingStack(BaseInfrastructure):
def create_resources(self):
functions = self.create_lambda_functions(function_props={"timeout": Duration.seconds(10)})
regular_bucket = s3.Bucket(
self.stack,
"S3Bucket",
removal_policy=RemovalPolicy.DESTROY,
auto_delete_objects=True,
block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
)
self.create_s3_deployment(regular_bucket)
for function in functions.values():
regular_bucket.grant_read(function)
CfnOutput(self.stack, "RegularBucket", value=regular_bucket.bucket_name)
versioned_bucket = s3.Bucket(
self.stack,
"S3VersionedBucket",
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
auto_delete_objects=True,
block_public_access=s3.BlockPublicAccess.BLOCK_ALL,
)
self.create_s3_deployment(versioned_bucket)
for function in functions.values():
versioned_bucket.grant_read(function)
CfnOutput(self.stack, "VersionedBucket", value=versioned_bucket.bucket_name)
def create_s3_deployment(self, bucket: s3.IBucket):
current_dir = Path(__file__).parent.resolve()
sources = [s3deploy.Source.asset(str(current_dir / "assets"))]
s3deploy.BucketDeployment(
self.stack,
f"Deployment{bucket.node.id}",
sources=sources,
destination_bucket=bucket,
)
|