小编cyb*_*rai的帖子

AWS CDK - 如何向现有 S3 存储桶添加事件通知

我正在尝试修改AWS 提供的 CDK 示例以改为使用现有存储桶。其他文档表明支持导入现有资源。到目前为止,我无法使用 CDK 向现有存储桶添加事件通知。

这是我修改后的示例版本:

class S3TriggerStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # create lambda function
        function = _lambda.Function(self, "lambda_function",
                                    runtime=_lambda.Runtime.PYTHON_3_7,
                                    handler="lambda-handler.main",
                                    code=_lambda.Code.asset("./lambda"))

        # **MODIFIED TO GET EXISTING BUCKET**
        #s3 = _s3.Bucket(self, "s3bucket")
        s3 = _s3.Bucket.from_bucket_arn(self, 's3_bucket',
            bucket_arn='arn:<my_region>:::<my_bucket>')

        # create s3 notification for lambda function
        notification = aws_s3_notifications.LambdaDestination(function)

        # assign notification for the s3 event type (ex: OBJECT_CREATED)
        s3.add_event_notification(_s3.EventType.OBJECT_CREATED, notification)
Run Code Online (Sandbox Code Playgroud)

这会在尝试时导致以下错误add_event_notification

AttributeError: '_IBucketProxy' object has …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-cdk

13
推荐指数
4
解决办法
1万
查看次数

标签 统计

amazon-web-services ×1

aws-cdk ×1