简体   繁体   English

aws cdk 没有为 lambda 创建 s3 触发器

[英]aws cdk not creating s3 trigger for lambda

I am trying to create a s3 trigger on a lambda using python cdk.我正在尝试使用 python cdk 在 lambda 上创建 s3 触发器。 I created lambda using cdk but it's working fine and other then that many other resources aswell created using cdk but on lambda it's not creating trigger my code is this:我使用 cdk 创建了 lambda 但它工作正常,除此之外还有许多其他资源也使用 cdk 创建但在 lambda 上它没有创建触发器我的代码是这样的:

import aws_cdk.aws_lambda_event_sources as eventsources
import aws_cdk.aws_s3 as s3


    my_lambda.add_event_source(
        eventsources.S3EventSource(
            mybucket,
            events=[s3.EventType.OBJECT_CREATED], 
            filters=[
                s3.NotificationKeyFilter(
                    prefix="start", 
                    suffix="mysufix.csv",
                ),
            ],
        )
    )

Try to create an instance of eventsources as S3EventSource is a class and addEventSource method needs IEventSource as source param尝试创建事件S3EventSource eventsources class 并且 addEventSource 方法需要IEventSource作为源参数

import aws_cdk.aws_lambda_event_sources as eventsources
import aws_cdk.aws_s3 as s3


my_lambda.add_event_source(
    new eventsources.S3EventSource(
        mybucket,
        events=[s3.EventType.OBJECT_CREATED], 
        filters=[
            s3.NotificationKeyFilter(
                prefix="start", 
                suffix="mysufix.csv",
            ),
        ],
    )
)

Docs: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.S3EventSource.html文档: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_event_sources.S3EventSource.html

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

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