将CloudFormation移植到Terraform:S3存储桶NotificationConfiguration

时间:2017-06-21 17:31:16

标签: terraform amazon-cloudformation

在将云信息模板移植到terraform并且无法将以下 NotificationConfiguration LambdaConfiguration 属性映射到其等效的等效格式的过程中。

 "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:*"]
 }
}

1 个答案:

答案 0 :(得分: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"
  }
}