将Cloudwatch日志复制到S3 |地形

时间:2019-08-20 09:48:34

标签: lambda terraform amazon-cloudwatch

点击下面的链接后,我可以创建IAM角色S3 Bucket,但是在调用Lambda函数时遇到了问题。

https://github.com/TeliaSoneraNorge/telia-terraform-modules/tree/master/cloudwatch-logs-s3-forwarder

错误:创建Lambda函数时出错:InvalidParameterValueException:无法解压缩上传的文件。请检查您的文件,然后尝试再次上传。     状态码:400,请求ID:b9363d94-53be-4116-915b-1cfe8faf61e6

在资源“ aws_lambda_function”“ logging_lambda_function”中的../../modules/s3/lambda.tf第11行上的

:   11:资源“ aws_lambda_function”“ logging_lambda_function” {

data "archive_file" "logging_lambda_function_zip_file" {
  type             = "zip"
  output_path      = "../../files/lambda/cloudwatch/logging.zip"

  source {
    content        = "${file("../../files/lambda/cloudwatch/logging.py")}"
    filename       = "logging.py"
  }
}

resource "aws_lambda_function" "logging_lambda_function" {
  filename         = "../../files/lambda/cloudwatch/logging.py"
  function_name    = "lamda_function"
  role             = "Iam_role_lambda"
  handler          = "logging.lambda_handler"
  source_code_hash = "${data.archive_file.logging_lambda_function_zip_file.output_base64sha256}"

  timeout          = 60
  runtime          = "python3.6"
  description      = "Export CloudWatch logs to S3 central bucket"

  environment {
    variables = {
      target_bucket = "bucket"
    }
  }

  depends_on = ["data.archive_file.logging_lambda_function_zip_file"]
}

resource "aws_lambda_permission" "allow_cloudwatch" {
  statement_id     = "AllowExecutionFromCloudWatch"
  action           = "lambda:InvokeFunction"
  function_name    = "${aws_lambda_function.logging_lambda_function.function_name}"
  principal        = "logs.amazonaws.com"
}

resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
  name            = "logfilter"
  log_group_name  = "/aws/lambda/stop-instances"
  filter_pattern  = "logtype test"
  destination_arn = "${aws_lambda_function.logging_lambda_function.arn}"
}

1 个答案:

答案 0 :(得分:0)

更新行,如下:-

filename         = "../../files/lambda/cloudwatch/logging.zip"