简体   繁体   English

如何从AWS SSM文档中正确引用Powershell脚本?

[英]How do I properly reference a Powershell script from an AWS SSM document?

The Amazon EC2 Simple Systems Manager documentation for the runPowerShellScript API call show how to specify a path to a PowerShell script for execution. runPowerShellScript API调用的Amazon EC2简单系统管理器文档显示了如何指定执行PowerShell脚本的路径。

I have tried to specify the full script path as indicated in the documentation: 我试图按照文档中的说明指定完整的脚本路径:

"runCommand":"c:\tools\GetTools.ps1",

but I get a syntax error when creating the document, even though the JSON document is correct: 但是即使JSON文档正确,我在创建文档时也会收到语法错误:

aws ssm create-document --content file://myssmdocument.json --name "runPSScript"

A client error (InvalidDocumentContent) occurred when calling the CreateDocument operation: JSON not well-formed. at Line: 12, Column: 29

What is the correct syntax? 正确的语法是什么?

The AWS documentation for the RunCommand parameter states: 适用于RunCommand参数的AWS文档指出:

"Specify the command to run or the path to an existing script on the instance." “指定要运行的命令或实例上现有脚本的路径。”

It appears the parameter does not actually accept a path. 看来参数实际上不接受路径。 It will generate an error as above if you provide one. 如果您提供一个,它将产生如上所述的错误。

The work around is to use only the script name in the runCommand parameter, and specify the full path in the WorkingDirectory 解决方法是仅在runCommand参数中使用脚本名称,并在WorkingDirectory中指定完整路径。

      "runCommand":"GetTools.ps1",
      "workingDirectory": "c:\tools"

This format will allow the ssm create-document command to run successfully. 这种格式将使ssm create-document命令成功运行。

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

相关问题 如何使用 Terraform 的 aws_ssm_document 在目标 VM 上运行 powershell 脚本 - How can I run a powershell script on a target VM using Terraform's aws_ssm_document 我在哪里/如何在 AWS SSM 自动化文档中定义 NotificationConfig? - Where/how do I define a NotificationConfig in an AWS SSM Automation document? AWS SSM RunCommand - RunRemoteScript 文档出现问题,以使用参数运行 PowerShell 脚本 - AWS SSM RunCommand - Issue with RunRemoteScript Document to run PowerShell script with parameters 如何每天执行 AWS SSM 自动化文档脚本? - How to execute AWS SSM automation document script daily? 如何使用 Terraform 将 powershell 命令传递给 AWS SSM 文档/运行命令? - How to pass a powershell command to AWS SSM Document/Run Command using Terraform? 如何在 Serverless 中引用 ssm 中的变量 - How do I reference a variable inside a ssm in Serverless 在 powershell 的 SSM 文档中引用 boolean 参数的正确方法是什么? - What is the correct way to reference a boolean parameter in SSM document for powershell? AWS SSM 文档自动化循环 - AWS SSM Document Automation loop 创建从 Parameter Store 中提取参数的 SSM 复合文档 - AWS - Creating a SSM Composite Document that pulls Parameters from Parameter Store - AWS AWS SSM 命令文档 - 限制可供选择的实例 - AWS SSM Command Document - Constrain instances to choose from
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM