Windows 上的 AWS CLI 无法使用,但使用双引号和转义



我制定了一个Amazon事件桥规则,并希望使用AWS CLI在其上附加目标。

我知道当你在windows 10命令提示符下的aws-cli中使用json字符串时,你需要

  1. 使用双引号。(现在允许使用单引号。(
  2. 除了第一个和最后一个外,在双引号前加上斜线

所以,我在命令提示符上调用这个

aws events put-targets --rule xxxxxxxxxxxxxxxxxxxxxxxxx --targets "{"Arn":"arn:aws:ssm:ap-northeast-1:awsaccountid:automation-definition/AWS-StartEC2Instance","Input":"{"InstanceId":["i-xxxxxxxxxxxxxxxxx"]}","Id":"aaaaaaaa","RoleArn":"arn:aws:iam::awsaccountid:role/some-ssm-role"}"

但出现错误:

Error parsing parameter '--targets': Invalid JSON: Expecting ',' delimiter: line 1 column 104 (char 103)
JSON received: {"Arn":"arn:aws:ssm:ap-northeast-1:awsaccountid:automation-definition/AWS-StartEC2Instance","Input":"{"InstanceId":["i-xxxxxxxxxxxxxxxxx"]}","Id":"aaaaaaaa","RoleArn":"arn:aws:iam::awsaccountid:role/some-ssm-role"}

有什么建议吗?

p.s.
我确保下面的命令在Linux终端上成功。

aws events put-targets --rule xxxxxxxxxxxxxxxxxxxxxxxxx --targets '{"Arn": "arn:aws:ssm:ap-northeast-1:awsaccountid:automation-definition/AWS-StopEC2Instance","Input":"{"InstanceId":["i-xxxxxxxxxxxxxxxxx"]}","Id":"aaaaaaaa","RoleArn":"arn:aws:iam::awsaccountid:role/some-ssm-role"}'

您可以尝试以下操作吗:

aws events put-targets --rule xxxxxxxxxxxxxxxxxxxxxxxxx --targets "{"Arn":"arn:aws:ssm:ap-northeast-1:awsaccountid:automation-definition/AWS-StartEC2Instance","Input":"{\"InstanceId\":[\"i-xxxxxxxxxxxxxxxxx\"]}","Id":"aaaaaaaa","RoleArn":"arn:aws:iam::awsaccountid:role/some-ssm-role"}"

或者,同样的东西,但这次使用插入符号连续标记稍微可读一些:

aws events put-targets ^
--rule xxxxxxxxxxxxxxxxxxxxxxxxx ^
--targets "{"Arn":"arn:aws:ssm:ap-northeast-1:awsaccountid:automation-definition/AWS-StartEC2Instance","Input":"{\"InstanceId\":[\"i-xxxxxxxxxxxxxxxxx\"]}","Id":"aaaaaaaa","RoleArn":"arn:aws:iam::awsaccountid:role/some-ssm-role"}"

需要识别的关键是JSON中的Input属性本身就是一个包含JSON的字符串,因此需要对其进行双转义。这至少通过了我的初始格式验证

相关内容

  • 没有找到相关文章

最新更新