【问题标题】:Porting CloudFormation to Terraform: S3 bucket NotificationConfiguration将 CloudFormation 移植到 Terraform:S3 存储桶 NotificationConfiguration
【发布时间】:2017-11-24 17:50:36
【问题描述】:

在将 cloudformation 模板移植到 terraform 的过程中,无法将以下 NotificationConfigurationLambdaConfiguration 属性映射到 terraform 中的等效属性。

 "CloudTrailS3Bucket" : {
  "DependsOn" : "TriggerLambdaPermission",
  "Type" : "AWS::S3::Bucket",
  "Properties" : {
    "BucketName" : { "Ref" : "CloudTrailBucketName" },
    "NotificationConfiguration" : {
      "LambdaConfigurations" : [
        {
          "Event" : "s3:ObjectCreated:*",
          "Function" : { "Fn::GetAtt" : [ "AutoTagLambdaFunction", "Arn" ] }
        }
      ]
    }
  }
}

到目前为止,我的 terraform 模块中的内容如下,但不确定我是否以正确的方式进行:

resource "aws_s3_bucket" "CloudTrailS3Bucket" {
 bucket = "${var.CloudTrailBucketName}"
}


resource "aws_s3_bucket_notification" "bucket_notification" {
 bucket = "${aws_s3_bucket.CloudTrailS3Bucket.id}"

 topic {
  topic_arn     = "${aws_sns_topic.topic.arn}"
  events        = ["s3:ObjectCreated:*"]
 }
}

【问题讨论】:

    标签: terraform amazon-cloudformation


    【解决方案1】:

    不,在 cloudformation 模板中,触发器是 lambda 事件 (s3:ObjectCreated),但在您的代码中,您使用简单通知服务 (SNS)

    请仔细阅读本文档中的部分

    s3 bucket notification - Add notification configuration to Lambda Function

    示例代码:

    resource "aws_s3_bucket" "bucket" {
      bucket = "your_bucket_name"
    }
    
    resource "aws_s3_bucket_notification" "bucket_notification" {
      bucket = "${aws_s3_bucket.bucket.id}"
    
      lambda_function {
        lambda_function_arn = "${aws_lambda_function.func.arn}"
        events              = ["s3:ObjectCreated:*"]
        filter_prefix       = "AWSLogs/"
        filter_suffix       = ".log"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 2021-03-01
      • 2018-03-09
      • 2020-12-04
      • 2011-12-15
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多