简体   繁体   中英

python cdk to create lambda trigger on s3 bucket

Hi I want to create a trigger on lambda function when a new json file is uploaded on s3 bucket. rule for trigger are

Trigger Rules for Lambda invocation using s3

**folder name** on which it will trigger is : input-files 
**file name**  ending with _processed.json OR 000.json 

I am trying this but not working and not sure about multiple rules for file ending

trigger-_lambda.add_event_source(_aws_lambda_event_sources.S3EventSource(
            bucket,
              events=[
                  _s3.EventType.OBJECT_CREATED],
              filters=[
                  _s3.NotificationKeyFilter(
                      prefix="input",
                      suffix="_processed.json" , "000.json ")]
            ))

is this the way to do this properly ? any help would be appreciated

S3 doesn't allow you to define multiple suffix rules in a filter.

To work around this, you would need to define two separate event sources:

my_lambda.add_event_source(
    lambda_event_sources.S3EventSource(
        bucket,
        events=[s3.EventType.OBJECT_CREATED],
        filters=[
            s3.NotificationKeyFilter(
                prefix="input",
                suffix="_processed.json",
            ),

        ],
    )
)
my_lambda.add_event_source(
    lambda_event_sources.S3EventSource(
        bucket,
        events=[s3.EventType.OBJECT_CREATED],
        filters=[
            s3.NotificationKeyFilter(
                prefix="input",
                suffix="000.json",
            ),
        ],
    )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM