I am trying to use boto3 to run a python file in my windows ec2 instance. I am trying to use AWS-RunPowerShellScript to run the following commands which both work when I rdp into my ec2 instance.
The code I am using: DoStuffOnEc2.py
import boto3
resp = client.send_command(
DocumentName="AWS-RunPowerShellScript", # One of AWS' preconfigured documents
Parameters={'commands': ['md test1', 'py -3 make_test_dir.py']},
InstanceIds=XXXXXXXXXX,
)
make_test_dir.py
import os
os.system('md test2')
When I run DoStuffOnEc2.py, only the test1 directory is created.
When I run md test1 and py -3 make_test_dir.py directly on Powershell while using an rdp, both test1 and test2 are created.
How would I go about resolving this. I generally use linux and have no experience with Powershell but I have to use it or CMD because the instance is Windows.
I also plan on moving this to AWS Lambda once it starts working but call a different python script. If there would be any issues with that, let me know.