Home > Enterprise >  Passing option value to AWS CLI command from variable or file
Passing option value to AWS CLI command from variable or file

Time:03-23

I am writing a script which creates various CloudFormation stacks, and want to start next stack when previous is done. Instead of 'sleep WHATEVER' I wish to use 'stack-exists' subcommand. ID of the stack in question is in StackId variable, and also is in StackId plaintext file. Here's the thing:

$ 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

Any ideas?

CodePudding user response:

Your StackId contains quotation marks. So it was created as :

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

rather then

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