【发布时间】:2022-06-13 13:47:01
【问题描述】:
我正在尝试创建一个处理参数的 SSM 文档,但我得到了
这是我的参数块:
"createfoo":{
"type": "Boolean",
"description": "Do you want to Create foo",
"default": false
}
这是我的 runCommand 块:
"mainSteps": [
{
"action": "aws:runPowerShellScript",
"name": "InstallGAIN",
"inputs":{
"runCommand": [
"[bool] $createfoo={{createfoo}}",
"if ($createfoo -eq $true) {",
"Write-Host \"Creating foo\"",
"}"
] } ]
Update-SSMDocument : 参数“createfoo”是“BOOLEAN”类型,不能用作 子字符串参数。 在 line:2 char:21
- $latestDocVersion = 更新-SSMDocument
- CategoryInfo : InvalidOperation: (Amazon.PowerShe...MDocumentCmdlet:UpdateSSMDo
cumentCmdlet) [更新-SSMDocument],InvalidOperationException + FullyQualifiedErrorId : Amazon.SimpleSystemsManagement.Model.InvalidDocumentContentExcep
化,Amazon.PowerShell.Cmdlets.SSM.UpdateSSMDocumentCmdlet
以下是我运行以更新我的文档的命令
$content = Get-Content -Path "installFoo.ssm" | Out-String
$latestDocVersion = Update-SSMDocument `
-Content $content `
-Name "installFoo" `
-DocumentFormat "JSON" `
-DocumentVersion '$LATEST' `
| Select-Object -ExpandProperty LatestVersion
Update-SSMDocumentDefaultVersion `
-Name "installFoo" `
-DocumentVersion $latestDocVersion
【问题讨论】:
-
@mklement0 谢谢,问题不在于我更新 SSM 文档的方式,而在于我如何尝试在 runcommand 块中使用参数的 (createfoo) 值 (false)。
-
根据错误消息和浏览文档(我不熟悉 AWS Systems Manager),看起来不允许在字符串中嵌入布尔参数,但您需要通过PowerShell 代码作为单个字符串(对吗?)。也许您可以将参数定义为 string。请注意,即使允许在
[bool] $createfoo={{createfoo}}中扩展createFoo,它也不会在 PowerShell 中工作,因为像[bool] $createfoo=true这样的东西会寻找true作为 命令;0或1可以工作 -
如果
{{createfoo}}扩展为true或false的字符串值,则必须使用[bool] $createfoo= if ('true' -eq '{{createfoo}}') { $true } else { $false }之类的东西
标签: amazon-web-services powershell aws-ssm