Installation and Setting Up
To install Boto3 on your computer, go to your terminal and run the following:
$ pip install boto3
You’ve got the SDK. But, you won’t be able to use it right now, because it doesn’t know which AWS account it should connect to.
To make it run against your AWS account, you’ll need to provide some valid credentials. If you already have an IAM user that has full permissions to S3, you can use that user’s credentials (their access key and their secret access key) without needing to create a new user. Otherwise, the easiest way to do this is to create a new AWS user and then store the new credentials.
00:00
To get started using Boto3, you first need to install it. From a new Python environment, go ahead to your terminal and run pip install boto3
.
00:16 And just like that, you’ve got the SDK. So you have Boto3 installed, but there’s no way for it to talk to your AWS account yet. I’m now going to go to my AWS account to show you how to create a user profile and allow Boto3 to connect to it.
00:34 Once you’ve logged into your AWS account, you’ll want to go ahead and find the IAM service.
00:43 From here, click on Users, and then add a user. It doesn’t matter what you call it, but I’m just going to name this one boto3user. What is important on this page is that you enable Programmatic access.
00:58 This is how your SDK is going to be able to communicate to the AWS API. From here, you can go ahead and set your permissions. And, in this case, you can just attach an existing policy directly.
01:14 Click on that, and then there’s quite a few in here, so if you just type in S3Full, you should see AmazonS3FullAccess. Make a check here, and what this policy is going to allow is for this user to have full control over anything related to S3, which is what you want. Go to Tags, which we’re going to skip, and then go to Review. On this page, you should see the user name that you put in, you should see that it has Programmatic access for its access type, and then if you go down to your Permissions summary, you should see this AmazonS3FullAccess policy. All right!
01:55
From here, you can go ahead and create the user. And then to get your access keys, you can download this CSV. This will download a CSV called credentials.csv
, which will contain everything you need for Boto3 to work with AWS.
02:14
I’m going to head back to the text editor, and I’ve gone and moved that CSV into my working folder right now. If you open that up, you should see a regular CSV, and it’s going to contain your User name
, which should match. Password
should actually just be an empty cell there, so you’ll just see two commas next to each other.
02:35
And then you’ll see the important stuff, this Access key ID
and Secret access key
. These are what Boto3 is going to use to connect to AWS.
02:45
Boto3 has a default area that it likes to look for these credentials. You can go ahead and make that folder by just calling mkdir
(make directory) and then put a tilda (~
), a slash (/
), and then .aws
.
03:04
And of course I’ve already created that, so I got an error there. But that’s okay. The file that Boto3 is going to look for is called credentials
.
03:14
Since I’m using the Atom text editor and have command line access to this, I’m just going to call atom
, go to that ~/.aws/
folder, and make a new file called credentials
.
03:36
And now this has opened up a new file for me. Copy and paste the following template. You should just have [default]
and then your access key ID and secret access key.
03:48 You’ll want to replace these all-caps sections with your actual values that you get from the CSV. So if I go back, I can see this is my access key ID, so I’m going to copy that.
04:08 Paste that in there, and then go back and grab this secret access key.
04:19
And paste that in there as well. Okay! This is ready to be saved. I’ve saved this and now within this .aws/
folder, I should have a credentials
file. From here, you’re going to need to make another configuration file to tell Boto3 which AWS region to use. I can do that from here, just make a new file and call this config
.
04:45 And like before, I’m going to paste in a template.
04:51
And in here, you’ll just see region
and YOUR_PREFERRED_REGION
. In my case, because I’m in Northern Virginia in the US, I’ll just put in us-east-1
.
05:03 AWS maintains a table of all the supported regions, so just go ahead and pick which one works best for your project. Save this file, and you’re all set for the rest of this tutorial.
05:15 Now that you’ve installed Boto3 and configured everything to work with S3, in the next video you’ll learn the two main ways that Boto3 allows you to work with S3 resources. Thanks for watching.
Become a Member to join the conversation.
alienpsp on May 4, 2020
Hey Joe and the RP family, will there be a boto3 tutorial update that covers the use of profile instead of AccessKey