Quick Start with Boto3 and AWS
In this post, we’ll take a look at some basics examples of using Python scripts to interact with the infrastructure provided by Amazon Web Services (AWS).
Take in count if you want to replicate this with your own AWS account, you will need:
- An AWS account with admin or power user privileges.
- Internet connection and Linux shell environment.
- Some experience with Python and Bash command line interface.
- An EC2 instance with Python, Boto3 and AWS CLI tool configured. You can use the Amazon Linux AMI which has all these packets.
After you setup your environment you can check is all is configured running the following command:
Where the yellow part is the instance ID of your EC2 instance.
Examples of how to use some basics scripts:
List Instances:
Results:
Create an Instance:
Results:
Terminate an Instance:
In this case the ID is our input for the terminate_instance.py
script.
Results:
Checking status of the instances:
Results:
Create a Bucket:
For this case we need to define the name of the bucket due to the restrictions and limitations of S3 (Bucket names must be globally unique and, Bucket names must follow DNS naming conventions).
Just playing…
There are a lot of ways to create different scripts, and every person will create and adapt the scripts based on their necessity. As last example here is one that I’ve made just playing with this:
This script will create an instance and wait until change the state to running, then create one file with the details of the instance and also it’s uploaded to our S3 bucket.
In conclusion boto3 can help you if you want to automate your AWS environment, in my particularly opinion it’s a great way to maintain your cloud environment well managed.
Link for the python scripts: HERE!
Thanks for read!!!