I have written the below powershell script in the userdata section of a AWS windows EC2 stack creation cloudformation script. I am able to install the AWSCLI using the script but the script is not recognizing 'aws s3 cp' command after install cmdlet. When I login to the EC2 instance I am able to run the aws s3 cp command sucessfully from the powershell prompt. Can anybody tell what I am doing wrong.
{
"contents":[
"<powershell> ","\n",
"$awscliurl = \"https://s3.amazonaws.com/aws-cli/AWSCLI64.msi\" \n",
"$awsclidownloadloc = \"C:/Windows/Temp/AWSCLI64.msi\" \n",
"(New-Object System.Net.WebClient).DownloadFile($awscliurl, $awsclidownloadloc) \n",
"$argstr = \"/I C:\\Windows\\Temp\\AWSCLI64.msi /quiet /L*v ./awscli-output.log\" \n",
"Start-Process msiexec.exe -Wait -ArgumentList $argstr \n",
"Start-Process powershell.exe -RedirectStandardOutput c:\\s3out.txt -RedirectStandardError c:\\s3err.out -Wait -ArgumentList \"aws s3 cp s3://mybucket/myfile.exe c:\\myfile.exe\" \n",
"</powershell>"
]
}
When I look at s3err.out I see the below
aws : The term 'aws' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + aws s3 cp s3://mybucket/myfile.exe c:\myfile.exe + ~~~ + CategoryInfo : ObjectNotFound: (aws:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException