Skip to content

Commit 0c61616

Browse files
use sns event source with prefix filter
1 parent f5a62b1 commit 0c61616

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

infra/aws/fiboa_sda.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
aws_ecs as ecs,
66
aws_ecr_assets as ecr_assets,
77
aws_lambda as _lambda,
8+
aws_lambda_event_sources as lambda_events,
89
aws_iam as iam,
910
aws_s3 as s3,
1011
aws_batch as batch,
1112
aws_s3_notifications,
13+
aws_sns as sns,
1214
Stack,
1315
Duration,
1416
Size,
@@ -84,16 +86,32 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
8486
directory=os.path.join(os.getcwd(), "lambda-image"),
8587
),
8688
)
87-
# create s3 bucket
88-
# bucket = s3.Bucket(self, "fiboa-sda-testing")
89-
bucket = s3.Bucket.from_bucket_name(self, "source-coop-bucket", bucket_name="us-west-2.opendata.source.coop")
9089

91-
# create s3 notification for lambda function
92-
notification = aws_s3_notifications.LambdaDestination(function)
93-
94-
# assign notification for the s3 event type (ex: OBJECT_CREATED)
95-
bucket.add_event_notification(
96-
s3.EventType.OBJECT_CREATED,
97-
notification,
98-
s3.NotificationKeyFilter(prefix="fiboa/*"),
90+
# add SNS event source
91+
topic = sns.Topic.from_topic_arn(
92+
self,
93+
"source-coop-topic",
94+
topic_arn="arn:aws:sns:us-west-2:417712557820:us-west-2-opendata-source-coop_new-object"
9995
)
96+
event_source = lambda_events.SnsEventSource(
97+
topic,
98+
filter_policy={
99+
"S3Key": sns.SubscriptionFilter.string_filter(match_prefixes=['fiboa'])
100+
}
101+
)
102+
function.add_event_source(event_source)
103+
104+
105+
# # create s3 bucket
106+
# # bucket = s3.Bucket(self, "fiboa-sda-testing")
107+
# bucket = s3.Bucket.from_bucket_name(self, "source-coop-bucket", bucket_name="us-west-2.opendata.source.coop")
108+
109+
# # create s3 notification for lambda function
110+
# # notification = aws_s3_notifications.LambdaDestination(function)
111+
112+
# # assign notification for the s3 event type (ex: OBJECT_CREATED)
113+
# bucket.add_event_notification(
114+
# s3.EventType.OBJECT_CREATED,
115+
# notification,
116+
# s3.NotificationKeyFilter(prefix="fiboa/*"),
117+
# )

0 commit comments

Comments
 (0)