Working with AWS using Python and Boto3: Setting Up Your Environment

aws_boto3_cover

Hi,

In this blog post, I’d like to show you how you can set up and prepare your development environment for AWS using Python and Boto3.

I’m assuming you’re familiar with AWS and have your Access Key and Secret Access Key ready; if that’s the case than great, either set them to your environment variables or wait up for me to show you how you can do that.

1. Python 3

If you already have Python 3 on your computer then you can skip this part entirely. For those who don’t; please go to Python Downloads Page and grab the latest Python 3 version for your operating system. And to make things simpler, get the standalone installer version which makes things a lot easier.

Once you have it, just launch the installer and follow the steps. It’s almost the same for Mac/Windows operating systems and once the installation completes make sure to check the box where it says Add Python to PATH (for Windows users). This is important; otherwise you’d have to do it manually.

Once you’re done with the installation, open a new Terminal window (for MacOS) or Command Prompt (for Windows) and type:

python --version

You should see a similar output like this (your version will probably be different):

2018-09-18 14_24_00-MINGW64__

Now we’re with Python and next up is to get boto3.

2. Boto3

Python comes with the pip, package manager for Python by default. Check if you already have it like below:

pip --version

You should have a similar output to this:

2018-09-18 14_29_07-MINGW64__

Once we verify that we have pip, we can install boto3 as follows:

pip install boto3

Once you run the command, it should install latest version of boto3. Since I already have it installed, my output looks like below but yours will take some time to collect packages and eventually install it:

2018-09-18 14_32_44-MINGW64__

3. IDE Configuration

IDEs are varying in features and functionalities and since you’re reading this, you probably have one that you like most. Mine is PyCharm and I think its the best Python IDE out there. If you want to use it or give it a try, go check it out at Jetbrains PyCharm Website , there’s also a free Community Edition available.

So for my IDE, PyCharm, I’ll open up a new project and select the existing Python interpreter as below:

2018-09-18 14_39_58-New Project

Once you have a similar configuration, now hit Create.

Project window opens up and now we can create our Python package to add our Python files in it. To do that, right-click on your project name and then New -> Python Package:

2018-09-18 14_42_58-my_python_project [D__my_python_project] - PyCharm (Administrator)

Name your package anything you want, I used src in my case. So let’s now create a new Python file following the same procedure by right-clicking and again name it anything you want. I named it boto3_test.py

Once you create your Python file, try to type in the following import statement:

2018-09-18 14_47_50-my_python_project [D__my_python_project] - ..._src_boto3_test.py [my_python_proj

If you could import boto3 like this than that’s great! We can move on to configure our IDE and write our first lines with boto3.

3.a AWS Credentials

If you have your AWS credentials ready on your environment then you can skip this part to the next. But if you don’t than let me show you how you can do that only for your specific project with PyCharm IDE. To configure your AWS credentials, click Add Configuration.. button on your IDE as below:

2018-09-18 14_54_40-

Then under Templates section, you’ll see Python when you expand it. Select it and add your AWS credentials under Environment Variables section like in the image above.

Save it preferrably and close the window when you’re done.

Now let’s type in our first line of code and get ready to work with AWS. To do that, you have couple of options with boto3. You can either make use of low-level client or higher-level resource declaration. I’ll show you either way.

In order to use low-level client for S3 with boto3, define it as follows:

s3_client = boto3.client('s3')

Instead, to use higher-level resource for S3 wih boto3, define it as follows:

s3_resource = boto3.resource('s3')

That’s it, you have your environment set up and running for Python Boto3 development. You’re ready to rock on with it!

Have a great day!

AWS with Python and Boto3: RDS PostgreSQL and DynamoDB CRUD course is out!

Do you want to learn how to launch managed Relational Databases or RDS on AWS? Do you want to learn how to connect to your RDS DB instances using Python and psycopg2 library and implement all Create, Read, Update and Delete (CRUD) operations? Or do you want to learn how to implement NoSQL DynamoDB Tables on AWS and work with data from scanning, querying to update, read and delete operations?

Then this is the course you need on RDS and DynamoDB on AWS!

In this course, we’ll start by taking a look at the tools and the environment that we need to work with AWS resources. We’ll be using Python 3 and as per the IDE I recommend you to use PyCharm from Jetbrains. It has a free community edition even!

After I teach you how you can set up your environment on both MacOS and Windows, we’ll create our credentials for AWS as being the AWS Access Key and AWS Secret Access Key for programmatic access to AWS resources. You’ll learn how you can set your AWS credentials globally on your computers using AWS CLI. Before jumping into the implementation, for one last tip, I’ll show you how you can have auto-complete capabilities on your PyCharm IDE with PyBoto3!

Once we’re ready with our environment setup, we’ll start implementing our solution on AWS! And remember we’ll do everything with Python code; not a single thing manually or by hand!

We’ll start off with RDS or Relational Database Service from AWS. I’ll teach you how to launch your own Amazon RDS Instances purely with your Python code! Then we’ll learn how to connect to our RDS database instance using Python and psycopg2 library. After that, I’ll teach you how to execute your queries against RDS PostgreSQL using psycopg2 library and we’ll implement SELECT, INSERT, DELETE, UPDATE so basically all the CRUD opreations against our own-launched RDS PostgreSQL instance on AWS!

Next up is DynamoDB! With this very-popular NoSQL service from AWS, I’ll teach you how to create your own DynamoDB Tables on AWS with Python! You’ll learn how to provide a key schema, attribute definitions and apply throughput to your tables.

And I’ll share the great news for you that there is a Local version of DynamoDB that you can simply run on your computer to play around with! I will show you how you can get and run the Local version of DynamoDB on your computer and we’ll setup our environment and boto3 client configuration accordingly.

Then we’ll start making our way to putting new items, updating, deleting and reading them. Once we learn the basic CRUD operations with DynamoDB, we’ll move on to rather advanced operations like scanning and querying.

We’ll also implement a script to insert our sample data set of “movies” into our DynamoDB Movies table! Once we insert the data, we’ll start exploring how we can search it using DynamoDB query operation and we’ll also learn how we can use conditions. And finally, we’ll take a look at the scan operation which basically scans your whole data and retriveves the results you need. So to filter out the results from scan operation, we’ll apply filter expressions to our scan operation and see how things work with DynamoDB.

Lots of information, hands-on practice and experience is waiting for you in this course on AWS. So, don’t miss any more time and join me in this course to sharpen your skills on AWS using Python and Boto3!

New course is out! AWS with Python and Boto3 Working with RDS and DynamoDB

Do you want to learn how to launch managed Relational Databases or RDS on AWS? Do you want to learn how to take snaphots, restore your DB instances and implement all of those with your Python code without even logging into AWS Console? Or Do you want to learn how to implement NoSQL DynamoDB Tables on AWS?

Then this is the course you need on RDS and DynamoDB on AWS!

In this course, we’ll start by taking a look at the tools and the environment that we need to work with AWS resources. We’ll be using Python 3 and as per the IDE I recommend you to use PyCharm from Jetbrains. It has a free community edition even!After I teach you how you can set up your environment on both MacOS and Windows, we’ll create our credentials for AWS as being the AWS Access Key and AWS Secret Access Key for programmatic access to AWS resources. You’ll learn how you can set your AWS credentials globally on your computers using AWS CLI. Before jumping into the implementation, for one last tip, I’ll show you how you can have auto-complete capabilities on your PyCharm IDE with PyBoto3!Once we’re ready with our environment setup, we’ll start implementing our solution on AWS! And remember we’ll do everything with Python code; not a single thing manually or by hand!We’ll start off with RDS or Relational Database Service from AWS. I’ll teach you how to launch your own Amazon RDS Instances purely with your Python code! Then we’ll learn how to Take a Snapshot or namely backup our complete database instance. After that, I’ll teach you how to restore that snapshot you have created earlier so you can recover your database from failures!Next up is DynamoDB! With this very-popular NoSQL service from AWS, I’ll teach you how to create your own DynamoDB Tables on AWS with Python! You’ll learn how to provide a key schema, attribute definitions and apply throughput to your tables.Lots of information, hands-on practice and experience is waiting for you in this course on AWS. So, don’t miss any more time and join me in this course to sharpen your skills on AWS using Python and Boto3!