-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3.py
More file actions
49 lines (41 loc) · 1.36 KB
/
Copy paths3.py
File metadata and controls
49 lines (41 loc) · 1.36 KB
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
from aws_cdk import RemovalPolicy, Stack
from aws_cdk.aws_lambda import Function, Runtime
from aws_cdk.aws_lambda_event_sources import S3EventSource
from aws_cdk.aws_s3 import Bucket, EventType
from aws_cdk.aws_sqs import Queue
from constructs import Construct
from infra.code import get_lambda_code
class S3SqsStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
queue = Queue(
self,
"DestinationQueue",
)
bucket = Bucket(
self,
"SourceBucket",
removal_policy=RemovalPolicy.DESTROY,
auto_delete_objects=True,
enforce_ssl=True,
)
function = Function(
self,
"S3SqsFunction",
runtime=Runtime.PYTHON_3_14,
handler="templates.s3.handler.main",
code=get_lambda_code(),
environment={
"SQS_QUEUE_URL": queue.queue_url,
"POWERTOOLS_SERVICE_NAME": "s3-sqs-processor",
"LOG_LEVEL": "INFO",
},
)
queue.grant_send_messages(function)
bucket.grant_read(function)
function.add_event_source(
S3EventSource(
bucket,
events=[EventType.OBJECT_CREATED],
)
)