繁体   English   中英

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

[英]ssm automation document input in AWS-RunShellScript not substituting variable

我试图在 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'

在上面的代码中。 我在 step1 中设置 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 操作中错误使用outputs引起的。 具体来说,lambda 操作没有如链接文档中所示的outputs属性:

name: invokeMyLambdaFunction
action: aws:invokeLambdaFunction
maxAttempts: 3
timeoutSeconds: 120
onFailure: Abort
inputs:
  FunctionName: MyLambdaFunction

相反,作为旁注, outputs属性在aws:executeAwsApi 中有效。

因此,解决方法是直接引用lambda 动作返回的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'

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM