【问题标题】:AWS CLI commands is not picking the ASG name from VaraibleAWS CLI 命令未从变量中选择 ASG 名称
【发布时间】:2021-01-13 09:00:05
【问题描述】:

您好,我在 powershell 中运行 AWS CLI 命令,但无法从变量传递 ASG 名称:


    $asgname = agaonline-system-ASG
    aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`Name`].Value, `$asgname`)].[AutoScalingGroupName]' --region eu-west-1 --output text | Out-File C:\temp\asg_name.txt

基本上,我无法将值 $asgname 传递给 AWS CLI 命令。

当我在命令下运行时,它给了我完美的输出:


    aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`Name`].Value, `agaonline-system-ASG`)].[AutoScalingGroupName]' --region eu-west-1 --output text | Out-File C:\temp\asg_name.txt

谁能帮帮我。

【问题讨论】:

  • 不确定查询字符串中的反引号,但是因为你在它周围使用了单引号,$asgname 不会被扩展。

标签: powershell aws-cli


【解决方案1】:

单引号不展开变量。使用双引号来做到这一点。 另外,我认为您不应该在查询字符串中使用 bakticks。

试试

"AutoScalingGroups[?contains(Tags[?Key=='Name'].Value, '$asgname')].[AutoScalingGroupName]"

【讨论】:

    猜你喜欢
    • 2021-07-23
    • 2021-10-22
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多