使用参数运行AWS Lambda的YAML SSM运行文档
我正在尝试从python aws lambda
中运行yaml ssm
文档,使用boto3 ssm.send_command_command
带有参数,但是即使我是只是想运行样本“ Hello World”,我就会得到:
“ errormessage”:“调用sendcommand操作时发生错误(无效的Parameters):document testmessage不支持参数。
RUN RUN DOMANTY无问题工作,因此似乎以JSON格式传递了这些参数,但是我打算的文档我打算打算使用。这包含一个相对较长的powershell脚本,json需要在一行上运行它,这很尴尬,我希望避免需要从S3存储桶中运行它。 lambda的参数?
I am trying to run a YAML SSM
document from a Python AWS Lambda
, using boto3 ssm.send_command
with parameters, but even if I'm just trying to run the sample "Hello World", I get:
"errorMessage": "An error occurred (InvalidParameters) when calling the SendCommand operation: document TestMessage does not support parameters.
JSON Run Documents work without an issue, so it seems like the parameters are being passed in JSON format, but the document I intend this for contains a relatively long Powershell script, JSON needing to run it all on a single line would be awkward, and I am hoping to avoid needing to run it from an S3 bucket. Can anyone suggest a way to run a YAML Run Document with parameters from the Lambda?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,AWS Lambda总是将其作为JSON的事件。我的建议是,在lambda_handler.py文件中声明这样的新变量:
这种方式将以yaml格式进行yaml格式,您可以使用该变量而不是以JSON格式的事件。
As far as I know AWS lambda always gets it's events as JSON. My suggestion would be that in the lambda_handler.py file declare a new variable like this:
This way the event will be in YAML format and you can use that variable instead of the event, which is in JSON format.
这是使用boto3
ssm.send_command
在运行python 3.8中运行yaml运行命令文档的示例。使用环境变量或SSM参数存储将变量传递给LAMBDA。该脚本从S3检索,并接受一个格式为JSON字符串的单个参数,该参数传递给了在Linux上运行的bash脚本(对不起,我没有PowerShell一个)。SSM文档是使用CloudFormation部署的,但您也可以通过控制台或CLI创建它。基于您引用的错误消息,也许验证文档类型被设置为“命令”。
SSM文档(用云形式模板包裹,请参阅
content
属性)json文档中的lambda函数
参数不一定在JSON本身中,它们很容易成为字符串或数字值(更可能是IMO)。如果要以JSON格式传递参数(与JSON文档不同),请注意引号并逃脱。
Here is an example of running a YAML Run Command document using boto3
ssm.send_command
in a Lambda running Python 3.8. Variables are passed to the Lambda using either environment variables or SSM Parameter Store. The script is retrieved from S3 and accepts a single parameter formatted as a JSON string which is passed to the bash script running on Linux (sorry I don't have one for PowerShell).The SSM Document is deployed using CloudFormation but you could also create it through the console or CLI. Based on the error message you cited, perhaps verify the Document Type is set as "Command".
SSM Document (wrapped in CloudFormation template, refer to the
Content
property)Lambda function
Parameters in a JSON document are not necessarily in JSON themselves, they can easily be string or numeric values (more likely IMO). If you want to pass a parameter in JSON format (not the same as a JSON document), pay attention to quotes and escaping.