简体   繁体   English

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

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

I am trying to run a command in bash where part of the command is substituted from a variable that I created in a previous step, however the string substitution is not working.我试图在 bash 中运行一个命令,其中命令的一部分由我在上一步创建的变量替换,但是字符串替换不起作用。 I have tried many variations of this with single, double quotes, etc but cant not get it to work.我已经用单引号、双引号等尝试了很多变体,但无法让它工作。

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'

In the above code.在上面的代码中。 I set asg_ips in step1 who's OutputPayload is as follows :我在 step1 中设置 asg_ips 谁的 OutputPayload 如下:

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

but for input in the 2nd step, it shows as follows...但是对于第二步的输入,它显示如下......

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

I need to get it to show something like this...我需要让它显示这样的东西......

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

Based on the comments.根据评论。

The issue was caused by incorrect use of outputs in aws:invokeLambdaFunction SSM action.该问题是由在aws:invokeLambdaFunction SSM 操作中错误使用outputs引起的。 Specifically, the lambda action does not have outputs attribute as shown in the linked documentation:具体来说,lambda 操作没有如链接文档中所示的outputs属性:

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

In contrast, as a side note, outputs attribute is valid in aws:executeAwsApi .相反,作为旁注, outputs属性在aws:executeAwsApi 中有效。

Therefore, the solution is to directly refer to the Payload returned by the lambda action:因此,解决方法是直接引用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'

The side effect is that now asg_ips.test needs to be post-processed to get the IP ranges values.副作用是现在需要对asg_ips.test进行后处理以获取 IP 范围值。

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

相关问题 如何在 EC2 实例上运行命令? SSM 中缺少 AWS-RunShellScript - How run a command on an EC2 instance? AWS-RunShellScript is missing from SSM AWS SSM 文档自动化循环 - AWS SSM Document Automation loop AWS-RunShellScript 调用 python 脚本,但找不到 python 模块 - AWS-RunShellScript calls python script but can't find python modules AWS Cloudformation SSM 自动化文档 | 与 aws cloudformation package 一起使用 - AWS Cloudformation SSM automation document | use with aws cloudformation package 如何每天执行 AWS SSM 自动化文档脚本? - How to execute AWS SSM automation document script daily? 我在哪里/如何在 AWS SSM 自动化文档中定义 NotificationConfig? - Where/how do I define a NotificationConfig in an AWS SSM Automation document? 带有私人信息的AWS SSM文档 - AWS SSM document with private information 使用参数从 AWS SSM 自动化执行 Lambda - Execute Lambda from AWS SSM Automation with Parameters SSM 自动化文档无法在 Lambda 调用结果上使用输出或 JSONPath - SSM Automation Document Unable to use Outputs or JSONPath on Lambda invoke results AWS SSM 自动化:如何在 aws:executeScript 调用的脚本中正常失败 - AWS SSM Automation: How to gracefully fail in script invoked by aws:executeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM