通过 Terraform 运行“aws stepfunctions update-state-machine"时出现 Json 解析错误 [英] Json parsing error when running 'aws stepfunctions update-state-machine' via Terraform

查看:22
本文介绍了通过 Terraform 运行“aws stepfunctions update-state-machine"时出现 Json 解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 这个问题,我尝试启用 X 射线并且它有效,我使用的代码:

I'm following the answer in this question, I tried to enable x-ray and it works, code I used:

resource "null_resource" "enable_step_function_logging" {
  triggers = {
state_machine_arn = aws_sfn_state_machine.sfn_state_machine.arn
  }
provisioner "local-exec" {
  command = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn} --tracing-configuration enabled=true"
  }
}

现在我想启用 cloudwatch 日志记录--logging-configuration=xxx"部分,但我不断收到错误消息.这是我尝试过的:

Now I want to enable cloudwatch logging ' --logging-configuration=xxx' part, but I keep getting errors. This is what I have tried:

resource "null_resource" "enable_step_function_logging" {
  triggers = {
    state_machine_arn = aws_sfn_state_machine.sfn_state_machine.arn
    logs_params       = <<PARAMS
      {
        "level":"ALL",
        "includeExecutionData":true,
        "destinations":[
            {
                "cloudWatchLogsLogGroup":{
                    "logGroupArn":"${aws_cloudwatch_log_group.sfn_cloudwatch_log_group.arn}:*"
                    }
                }
            ]
            }
    PARAMS
  }
  provisioner "local-exec" {
    command     = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn}  --tracing-configuration enabled=true --logging-configuration='${self.triggers.logs_params}'"
  }
}

然后当我在 Terraform 中申请时,它给了我错误:

Then when I apply in Terraform, it gave me error:

Error: Error running command 'aws stepfunctions update-state-machine --state-machine-arn arn:aws:states:us-east-1:xxxxxxxxx:stateMachine:xxxxxxxxstate-machine  --tracing-configuration enabled=true --logging-configuration='      {
        "level":"ALL",
        "includeExecutionData":true,
        "destinations":[
            {
                "cloudWatchLogsLogGroup":{
                    "logGroupArn":"arn:aws:logs:us-east-1:xxx:log-group:/aws/vendedlogs/states/xxxxxxx-Logs:*"
                    }
                }
            ]
            }
'': exit status 252. Output:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

Unknown options: {

这是抱怨aws命令的格式无效,我在网上找不到任何示例,有人可以帮忙吗?

It's comlaining the invalid format of the aws command, I couldn't find any examples online, can someone help please?

推荐答案

从来没有在 windows 上使用过 terraform 我有点不清楚,但我怀疑 local-exec 正在使用 cmd 而不是 bash 来运行 aws-cli.事物的转义和解释方式可能有所不同?尝试告诉 terraform 使用 bash:

Having never used terraform with windows I'm a bit unclear, but i suspect local-exec is using cmd rather than bash to run the aws-cli. There may be differences in how things are escaped and interpreted? Try telling terraform to use bash:

  provisioner "local-exec" {
    command     = "aws stepfunctions update-state-machine --state-machine-arn ${self.triggers.state_machine_arn}  --tracing-configuration enabled=true --logging-configuration='${self.triggers.logs_params}'"
    interpreter = ["bash", "-c"]
  }

这篇关于通过 Terraform 运行“aws stepfunctions update-state-machine"时出现 Json 解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆