I'm using aws ec2 service with awscli. Now I want to put all the commands I type in the console into a python script. I see that if I write import awscli
inside a python script it works fine but I don't understand how to use it inside the script. For instance how do I execute the commands aws ec2 run-instances <arguments>
inside the python script after import awscli
? Just to make it clear, I'm not looking for a solution like os.system('aws ec2 run-instances <arguments>')
, I'm looking for something like
import awscli
awscli.ec2_run-instances(<arguments>)
The AWS CLI and AWS SDK for Python will require Python 2.7+ or 3.4+ as their Python runtime. On January 10, 2020, in order to continue supporting our customers with tools that are secure and maintainable, AWS will publish a minor version bump of the AWS CLI and AWS SDK for Python (Boto3 and Botocore).
You can do it with brilliant sh package. You could mimic python package with sh doing wrapping for you.
import sh
s3 = sh.bash.bake("aws s3")
s3.put("file","s3n://bucket/file")
The CLI would be more suited for the shell prompt, for a better python API, check the boto library. This example shows how to launch an instance: http://boto.readthedocs.org/en/latest/ec2_tut.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With