[英]aws lambda - How to add s3 trigger using cloudformation if the s3 bucket is created manually
[英]AWS Lambda S3 Bucket Notification via CloudFormation
我正在嘗試通過CloudFormation創建Lambda通知,但是收到有關ARN格式錯誤的錯誤。
我的CloudFormation錯誤或者它還不支持Lambda預覽。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"LambdaArn": {
"Type": "String",
"Default": "arn:aws:lambda:{some-region}:{some-account-id}:function:{some-fn-name}"
}
},
"Resources": {
"EventArchive": {
"Type": "AWS::S3::Bucket",
"Properties": {
"NotificationConfiguration": {
"TopicConfigurations": [
{
"Event": "s3:ObjectCreated:Put",
"Topic": {
"Ref": "LambdaArn"
}
}
]
}
}
}
}
}
但是當我推動這個CloudFormation時,我收到了消息:
The ARN is not well formed
有沒有人知道這意味着什么? 我知道上面的例子已被修改,所以不使用我的實際 ARN,但在我的實際代碼中,我直接從GUI復制了ARN。
此外,有趣的是我能夠通過AWS控制台創建通知,因此我只是假設AWS CloudFormation尚不支持此功能(即使這並不十分清楚我在閱讀文檔時沒有想到)。
看起來AWS現在已經發布了對在CloudFormation中直接通知lambda函數的支持。
S3 NotificationConfiguration
定義過去僅包含TopicConfigurations,但已更新為包括LambdaConfigurations
。
添加NoficationConfiguration后,請確保包含Lambda :: Permission資源,以便允許S3執行lambda函數。 以下是可用作模板的示例權限:
"PhotoBucketExecuteProcessorPermission": {
"Type" : "AWS::Lambda::Permission",
"Properties" : {
"Action":"lambda:invokeFunction",
"FunctionName": { "Fn::GetAtt": [ "PhotoProcessor", "Arn" ]},
"Principal": "s3.amazonaws.com",
"SourceAccount": {"Ref" : "AWS::AccountId" },
"SourceArn": {
"Fn::Join": [":", [
"arn","aws","s3","", ""
,{"Ref" : "PhotoBucketName"}]]
}
}
}
來自文檔 :
Amazon S3報告指定事件的Amazon SNS主題。
看起來雖然S3支持向Lambda發送事件 ,但CloudFormation還沒有趕上。 它期望您提供Lambda函數ARN的SNS ARN。
目前,您似乎必須手動連接事件通知。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.