Amazon web services AWS RunShellScript中的ssm自动化文档输入不替换变量

Amazon web services AWS RunShellScript中的ssm自动化文档输入不替换变量,amazon-web-services,aws-ssm,Amazon Web Services,Aws Ssm,我试图在bash中运行一个命令,其中部分命令是从我在上一步中创建的变量中替换的,但是字符串替换不起作用。我尝试了很多单引号、双引号等的变体,但都没能成功 mainSteps: - name: getIps action: 'aws:invokeLambdaFunction' timeoutSeconds: 1200 maxAttempts: 1 onFailure: Abort inputs: FunctionName: Automatio

我试图在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,其输出有效负载如下所示:

{"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"]}
根据评论

该问题是由于在SSM操作中不正确使用
输出造成的。具体而言,lambda操作没有链接文档中所示的
输出
属性:

name: invokeMyLambdaFunction
action: aws:invokeLambdaFunction
maxAttempts: 3
timeoutSeconds: 120
onFailure: Abort
inputs:
  FunctionName: MyLambdaFunction
相反,作为旁注,
输出
属性在中有效

因此,解决方案是直接引用lambda操作返回的
有效负载

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'

副作用是,现在需要对asg_ips.test进行后处理以获得IP范围值。

您是否有任何参考资料可供您使用
aws:invokeLambdaFunction
中的
输出
?中国没有这样的领域。因此,如果您执行
'echo{{getIps.Payload}}>/root/asg_ips.test'
,它将工作,但显然需要处理asg_ips.test文件以从完整负载中获取ip值。这似乎是我的问题。谢谢没问题。如果你不介意的话,我会提供一个答案供将来参考。只是想知道事情进展如何?