|
5 | 5 | aws_ecs as ecs, |
6 | 6 | aws_ecr_assets as ecr_assets, |
7 | 7 | aws_lambda as _lambda, |
| 8 | + aws_lambda_event_sources as lambda_events, |
8 | 9 | aws_iam as iam, |
9 | 10 | aws_s3 as s3, |
10 | 11 | aws_batch as batch, |
11 | 12 | aws_s3_notifications, |
| 13 | + aws_sns as sns, |
12 | 14 | Stack, |
13 | 15 | Duration, |
14 | 16 | Size, |
@@ -84,16 +86,32 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: |
84 | 86 | directory=os.path.join(os.getcwd(), "lambda-image"), |
85 | 87 | ), |
86 | 88 | ) |
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") |
90 | 89 |
|
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" |
99 | 95 | ) |
| 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