【发布时间】:2020-09-17 18:38:34
【问题描述】:
我正在尝试在 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中的outputs的使用有什么参考吗? aws docs 中没有这样的字段。因此,如果您执行'echo {{getIps.Payload}} > /root/asg_ips.test',它将起作用,但显然需要处理 asg_ips.test 文件以从完整有效负载中获取 ip 值。 -
这看起来是我的问题。谢谢!
-
没问题。如果您不介意,我会提供答案以供将来参考。
-
嗨。只是想知道进展如何?
标签: amazon-web-services aws-ssm