簡體   English   中英

如何在 cdk python 中觸發 s3 復制 cli 復制事件?

[英]How to trigger s3 copy cli copy events in cdk python?

我應該使用什么EventType 嘗試了所有 CREATED 屬性,例如OBJECT_CREATED_PUT但無法捕獲任何事件。

$ aws s3 cp./testFile.txt s3://.... >> CloudWatch > 日志 > 收到的事件:{}

應用程序.py

from aws_cdk import aws_s3 as _s3

output_s3 = _s3.Bucket(self,
                       "output_s3",
                       removal_policy=core.RemovalPolicy.DESTROY,
                       auto_delete_objects=True)

# allows the instance to read/write files
output_s3.grant_read_write(instance)

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

output_s3.add_event_notification(
    _s3.EventType.OBJECT_CREATED_COMPLETE_MULTIPART_UPLOAD,
    notification)

output_s3.add_event_notification(_s3.EventType.OBJECT_CREATED_PUT,
                                 notification)

lambda_handler.py

import json

def main(event, context):
    print("Received event: " + json.dumps(event, indent=2))
    return json.dumps(event, indent=2)
我應該使用什么事件類型?

_s3.EventType.OBJECT_CREATED是在任何創建事件上觸發的全部內容。

為什么觸發的 Lambda 接收到空事件?

如果CloudWatch正在記錄Received event: {} ,則表示觸發器正在觸發但事件為空。 這很奇怪。 這可能是都市傳說,但我聽說刪除和重新創建通知會有所幫助。 AWS 相當於“您是否嘗試過將其關閉再打開”... cdk destroy , cdk deploy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM