如何解决通过 Terraform 运行“aws stepfunctions update-state-machine”时出现 Json 解析错误
我正在关注 this question 中的答案,我尝试启用 X 射线并且它有效,我使用的代码:
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' 部分,但我不断收到错误消息。这是我尝试过的:
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}'"
}
}
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","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 命令格式无效,我在网上找不到任何示例,有人可以帮忙吗?
解决方法
从未在 Windows 上使用 terraform 我有点不清楚,但我怀疑 local-exec
正在使用 cmd
而不是 bash
来运行 aws-cli。事物的转义和解释方式可能存在差异?尝试告诉 terraform 使用 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"]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。