[英]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.