I have an SSM document that I am using to run a PowerShell script and then invoke another SSM document. I want to pass output from the first SSM document to the second document.
{
"schemaVersion": "2.2",
"description": "This is to test copying a file from place a to b",
"parameters": {
"InputDir": {
"type": "String",
"description": "This is the input directory from where we are copying",
"default": "C:\\himanshu\\AWS_SSM_WORK"
},
"OutputDir": {
"type": "String",
"description": "This is the output directory where to we are copying",
"default": ""
}
},
"mainSteps": [
{
"action": "aws:runPowerShellScript",
"name": "testCopyFunction",
"inputs": {
"timeoutSeconds": "60",
"runCommand": [
"write-Output {{InputDir }}",
" $utility_path = '{{InputDir}}'",
"$var = @{",
" “name” = “himanshu” ",
" “surname” = “rai” ",
"}",
" if (Test-Path $utility_path) ",
" { Set-Location $utility_path ",
" Start-Process \"cmd.exe\" \" /k C:\\himanshu\\AWS_SSM_WORK\\start.bat \" ",
" $var.Add(\"state\",\"up\") ",
"}",
" else ",
" { Write-Error \"Base location of build is incorrectly set.\" ",
" exit 1",
" }",
"$var | ConvertTo-Json | Out-File \".\\name.json\" "
]
}
},
{
"action": "aws:runDocument",
"name": "egsl_him_second",
"inputs": {
"documentType": "SSMDocument",
"documentPath": "egsl_him_second",
"documentParameters": {
"InputDir": "C:\\himanshu\\AWS_SSM_WORK"
},
"finallyStep": true
}
}
]
}
In the second step, I am calling another SSM document using aws:runDocument. Is there any way, I can use the $var in the second step that I have created in step1
Upping my comment to a full answer. Assuming OP is using Command documents (which I presume from the fact that they are using aws:runPowerShellScript
, which is a Command document plugin), the answer is that as of this writing (more than two years later) you cannot do this with Command documents. The documentation that the downvoted answer referred to applies to Automation documents, which are much more powerful.
I asked this question directly to AWS Support and was linked to this very page before they realized the distinction between Command and Automation documents, and after testing on their side they explicitly confirmed that this cannot be done with Command documents.