【问题标题】:Copy Cloudwatch logs to S3 | Terraform将 Cloudwatch 日志复制到 S3 |地形
【发布时间】:2019-12-25 12:16:52
【问题描述】:

点击以下链接后,我可以创建 IAM 角色、S3 存储桶,但在调用 Lambda 函数时遇到问题。

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

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

在 ../../modules/s3/lambda.tf 第 11 行,资源“aws_lambda_function”“logging_lambda_function”中: 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}"
}

【问题讨论】:

    标签: lambda terraform amazon-cloudwatch


    【解决方案1】:

    更新的行如下:-

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2020-02-27
      • 2019-11-01
      • 2018-02-10
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      相关资源
      最近更新 更多