小编LHK*_*LHK的帖子

如何通过 Terraform 设置 aws cloudwatch 保留

使用 Terraform 部署 API Gateway/Lambda 并且在 Cloudwatch 中已经有了相应的日志。但是,我似乎无法找到一种使用当前部署的资源(如下)通过 Terraform 设置日志保留的方法。看起来日志组资源是我要做的地方,但不确定如何将来自 api 网关的日志流指向新的日志组。我一定遗漏了一些明显的东西......非常感谢任何建议!

resource "aws_api_gateway_account" "name" {
  cloudwatch_role_arn = "${aws_iam_role.cloudwatch.arn}"
}

  resource "aws_iam_role" "cloudwatch" {
    name = "#{name}_APIGatewayCloudWatchLogs"
    assume_role_policy = <<EOF
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Sid": "",
     "Effect": "Allow",
     "Principal": {
     "Service": "apigateway.amazonaws.com"
    },
    "Action": "sts:AssumeRole"
  }
 ]
}
  EOF
  }

resource "aws_iam_policy_attachment" "api_gateway_logs" {
  name = "#{name}_api_gateway_logs_policy_attach"
  roles = ["${aws_iam_role.cloudwatch.id}"]
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
}  

resource "aws_api_gateway_method_settings" "name" {
  rest_api_id = "${aws_api_gateway_rest_api.name.id}"
  stage_name  = "${aws_api_gateway_stage.name.stage_name}"
  method_path = "${aws_api_gateway_resource.name.path_part}/${aws_api_gateway_method.name.http_method}"

  settings …
Run Code Online (Sandbox Code Playgroud)

amazon-cloudwatch terraform aws-api-gateway

6
推荐指数
1
解决办法
1678
查看次数