【问题标题】:How do I update an AWS cloudwatch sythetic canary via terraform?如何通过 terraform 更新 AWS cloudwatch 合成金丝雀?
【发布时间】:2022-10-12 22:22:49
【问题描述】:

我通过 terraform 创建了一个金丝雀。我现在正在尝试通过 terraform 更新金丝雀脚本。我将我的脚本直接输入到金丝雀中。我已经包含一个带有触发器的空资源,该触发器总是重新创建我的 zip 文件。我的金丝雀脚本/ lambda 层没有更新。我想知道如何触发更新以使用新的脚本版本?到目前为止,我发现唯一可以工作的是 terraform destroy/apply。

我知道 cli update-canary 命令和 s3 选项。理想情况下,我希望继续将我的脚本直接输入到金丝雀中。

resource "null_resource" "script-zip" {
  provisioner "local-exec" {
    command     = <<EOT
      zip -r ./recordedScript.zip nodejs/node_modules/
    EOT
    working_dir = path.module
  }
  triggers = {
    always_run = "${timestamp()}"
  }
}

resource "aws_synthetics_canary" "canary" {
  name                 = var.synthetic-name
  artifact_s3_location = "s3://${aws_s3_bucket.synthetics-bucket.id}"
  execution_role_arn   = aws_iam_role.synthetics_role.arn
  handler              = var.handler
  zip_file             = "${path.module}/recordedScript.zip"
  runtime_version      = var.runtime-version
  start_canary         = var.start-canary
  depends_on = [
    resource.null_resource.script-zip
  ]

【问题讨论】:

    标签: amazon-web-services amazon-cloudwatch-synthetics


    【解决方案1】:

    似乎 aws_synthetics_canary 资源没有查看创建的 zip 文件的哈希值。我可以通过给每个创建的 zip 文件一个唯一的名称来解决这个问题。

    locals {
      NOW = "${timestamp()}"
    }
    
    resource "null_resource" "script-zip" {
      provisioner "local-exec" {
        command     = <<EOT
          zip -r ./${local.NOW}-recordedScript.zip nodejs/node_modules/
        EOT
        working_dir = path.module
      }
      triggers = {
        always_run = "${timestamp()}"
      }
    }
    
    
    resource "aws_synthetics_canary" "canary" {
      name                 = var.synthetic-name
      artifact_s3_location = "s3://${aws_s3_bucket.synthetics-bucket.id}"
      execution_role_arn   = aws_iam_role.synthetics_role.arn
      handler              = var.handler
      zip_file             = "${path.module}/${local.NOW}-recordedScript.zip"
      runtime_version      = var.runtime-version
      start_canary         = var.start-canary
    
      depends_on = [
        resource.null_resource.script-zip
      ]
    
    
      schedule {
        expression = var.schedule
      }
    
      run_config {
        environment_variables = var.env-vars
        timeout_in_seconds    = var.timeout
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-07-28
      • 2022-06-28
      • 2021-02-12
      • 2018-02-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      相关资源
      最近更新 更多