将选项值从变量或文件传递给 AWS CLI 命令

Passing option value to AWS CLI command from variable or file

我正在编写一个创建各种 CloudFormation 堆栈的脚本,并希望在完成上一个堆栈后启动下一个堆栈。我希望使用 'stack-exists' subcommand 而不是 'sleep WHATEVER'。有问题的堆栈的 ID 在 StackId 变量中,也在 StackId 明文文件中。 事情是这样的:

$ echo ${StackId}
"arn:aws:cloudformation:eu-central-1:461950495720:stack/CF-VPC-NEW/8031d670-aa78-11ec-986e-02784df577a8"
$ aws cloudformation wait stack-exists  --stack-name ${StackId}

Waiter StackExists failed: Max attempts exceeded. Previously accepted state: Matched expected service error code: ValidationError
$ cat StackId
"arn:aws:cloudformation:eu-central-1:461950495720:stack/CF-VPC-NEW/8031d670-aa78-11ec-986e-02784df577a8"
$ aws cloudformation wait stack-exists  --stack-name `cat StackId`

Waiter StackExists failed: Max attempts exceeded. Previously accepted state: Matched expected service error code: ValidationError
$ aws cloudformation wait stack-exists  --stack-name "arn:aws:cloudformation:eu-central-1:461950495720:stack/CF-VPC-NEW/8031d670-aa78-11ec-986e-02784df577a8"
$ echo $?
0

有什么想法吗?

您的 StackId 包含 引号 。所以它被创建为:

StackId=\"arn:aws:cloudformation:eu-central-1:461950495720:stack/CF-VPC-NEW/8031d670-aa78-11ec-986e-02784df577a8\"

而不是

StackId="arn:aws:cloudformation:eu-central-1:461950495720:stack/CF-VPC-NEW/8031d670-aa78-11ec-986e-02784df577a8"