AWS-RunShellScript中的ssm自动化文档输入未替换变量

问题描述

我正在尝试在bash中运行命令,该命令的一部分已从我在上一步中创建的变量中替换,但是字符串替换不起作用。我已经尝试过用单引号,双引号等对它进行多种变体,但无法使其正常工作。

mainSteps:
  - name: getIps
    action: 'aws:invokeLambdaFunction'
    timeoutSeconds: 1200
    maxAttempts: 1
    onFailure: Abort
    inputs:
      FunctionName: Automation-GetIPs
      Payload: '{"asg": "Staging_web_ASG"}'
    outputs:
      - Name: asg_ips
        Selector: $.Payload.IPs
        Type: StringList
  - name: updatelsync
    action: 'aws:runcommand'
    timeoutSeconds: 1200
    inputs:
      DocumentName: AWS-RunShellScript
      InstanceIds:
        - '{{ InstanceID }}'
      Parameters:
        commands:
          - 'echo {{getIps.asg_ips}} > /root/asg_ips.test'

在上面的代码中。我在步骤1中设置了asg_ips,其OutputPayload如下:

{"Payload":{"IPs": ["172.xx.x.xxx","172.xx.x.xxx"]},"StatusCode":200}

但在第二步中输入时,显示如下...

{"commands":["echo {{getIps.asg_ips}} > /root/asg_ips.test"]}

我需要让它显示类似这样的内容...

{"commands":["echo ["172.xx.x.xxx","172.xx.x.xxx"] > /root/asg_ips.test"]}

解决方法

基于评论。

此问题是由于在aws:invokeLambdaFunction SSM操作中错误使用git checkout master git pull origin master git checkout [branch] git rebase master git push --force-with-lease 引起的。具体来说,lambda操作不具有链接文档中所示的outputs属性:

outputs

相反,作为补充,name: invokeMyLambdaFunction action: aws:invokeLambdaFunction maxAttempts: 3 timeoutSeconds: 120 onFailure: Abort inputs: FunctionName: MyLambdaFunction 属性在aws:executeAwsApi中有效。

因此,解决方案是直接引用到lambda操作返回的outputs

Payload

副作用是现在mainSteps: - name: getIps action: 'aws:invokeLambdaFunction' timeoutSeconds: 1200 maxAttempts: 1 onFailure: Abort inputs: FunctionName: Automation-GetIPs Payload: '{"asg": "Staging_web_ASG"}' - name: updatelsync action: 'aws:runCommand' timeoutSeconds: 1200 inputs: DocumentName: AWS-RunShellScript InstanceIds: - '{{ InstanceID }}' Parameters: commands: - 'echo {{getIps.Payload}} > /root/asg_ips.test' 需要进行后处理以获取IP范围值。