简体   繁体   English

python cdk 在 s3 存储桶上创建 lambda 触发器

[英]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.您好我想在 s3 存储桶上上传新的 json 文件时在 lambda 函数上创建触发器。 rule for trigger are触发规则是

Trigger Rules for Lambda invocation using s3使用 s3 触发 Lambda 调用规则

**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. S3 不允许您在过滤器中定义多个后缀规则。

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",
            ),
        ],
    )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Python处理Lambda中的S3 Bucket Trigger事件 - Handling S3 Bucket Trigger Event in Lambda Using Python 在 Python 中使用 CDK 进行 S3 存储桶复制 - S3 Bucket replication using CDK in Python 当新对象到达S3存储桶时触发Lambda函数 - Trigger Lambda function when a new object arrives in S3 bucket AWS Lambda和S3和Pandas-将CSV加载到S3中,触发Lambda,加载到pandas,放回存储桶中? - AWS Lambda and S3 and Pandas - Load CSV into S3, trigger Lambda, load into pandas, put back in bucket? Python 中的 AWS Lambda 将新文件复制到另一个 s3 存储桶 - AWS Lambda in Python to copy new files to another s3 bucket AWS Lambda 使用 python 读取 S3 存储桶中的文件 - AWS Lambda read a file in the S3 bucket using python 根据将文件从一个 S3 存储桶复制到另一个存储桶的清单文件触发 AWS Lambda function - Trigger AWS Lambda function based on a manifest file which copies files from one S3 bucket to another 是否有Lambda触发器将文件从S3存储桶推送/复制到SFTP服务器? - Is there a Lambda trigger that will push/copy files from S3 bucket to the SFTP server? AWS Lambda 在 S3 存储桶上触发 Neptune“无法为源启动新负载” - AWS Lambda trigger on S3 bucket to Neptune "Failed to start new load for the source" 带有 S3 触发器的 Lambda 返回 NoSuchKey 错误(Python) - Lambda with S3 trigger returning NoSuchKey error (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM