Python is a beginner-friendly, high-level programming language which is easily readable. It was created in the 1980s by Guido van Rossum and was coined Python because he liked the humour of the Monty Python comedy group.
It's one of the most popular languages in the world and is widely used for creating websites, games, etc. Due to its easy-to-learn nature, it has achieved widespread adoption. Python can also do things like math, creating pictures, decoding pictures, scraping data, etc., and can also be used in training AI models.
The Boto library is the AWS Software Development Kit (SDK) for Python that allows us to create, configure, and manage AWS services using APIs. The SDK provides API and low-level access to AWS.
Boto3 relies on the botocore library to handle low-level operations that are required to send secure API requests to AWS. The received XML responses are then transformed to Dictionary Type. Using Boto3, we can write Python scripts to automate various tasks with AWS, including:
Provisioning and managing Amazon Elastic Compute Cloud (EC2) instances
Storing and retrieving data from Amazon Simple Storage Service (S3)
Setting up and managing Amazon Virtual Private Clouds (VPCs)
Sending and receiving emails using Amazon Simple Email Service (SES) and much more
Overall, using Boto3 and Python to automate AWS infrastructure can save us time and effort and help in managing resources more efficiently.
Let's create a bot that can create and delete S3 resources (bucket & objects).
Create a file called bot.py and paste the following code into it.
This code contains all the required functions for performing bucket creation, bucket deletion and object deletion operations.
If you need to delete a bucket, you must delete all the objects (data) inside the bucket as well. This is required, so we don't accidentally delete a bucket with data.
Run the App
Now, run the application using the command below:
Communicate with the Bot
Now that our bot is running let's provide some commands to the discord bot.
For Creating Bucket
For Deleting Bucket
These commands are to be provided to the discord bot we created via Direct Message or by mentioning it in the channel we authorized it on.
In this article, we learned to code a python application which controls AWS infrastructure according to the user's requirements. We learned to use libraries like Boto3, Logging, Discord, etc., to create our application.
In the next article, we will learn to implement AWS Lambda Functions and API Gateway in our Python Application.
Thanks for reading! Please drop any queries you have below, I'll periodically keep updating this article to maintain it's authenticity.