簡體   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