How-to: Upload Files to Amazon S3 via an API
--
Background
Amazon S3 is a highly-utilized and well-known object storage service offered by Amazon Web Services (AWS). It is virtually used for everything, from storing data related to application logs, to gigabyte-sized media files.
High-Level Solution Architecture
Manually Upload to S3? Nah, ain’t nobody got time for that… 👎
AWS makes it super easy to utilize S3. You can just create your bucket, and upload whatever data you want into it.
But, what if… instead of manually navigating to our bucket, we upload objects into it through invoking an API? 😃
API to the rescue! 🦸
Having an API to upload data into S3 will enable:
- LESS manual work 💪
- Consumer-friendly interaction
- Quicker process to upload
- API-reusability
Let’s go build our API!
We will be building our file upload solution using the following AWS Services:
Step 1 — Create an IAM Role with the required policy permissions
This role will consist of a policy that will allow our API to upload files into our S3 Bucket through an API Gateway endpoint.
Make sure your policy looks similar to what I have shared below:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::file-upload-bucket/*"
}
]
}
Step 2 — Create the API Gateway
Now, we are going to a create an API Gateway that will be the entry to our File Uplaod API.
As shown below, the folder and file resources here represent our S3 Bucket and S3 Object respectively.
These resources will serve as parameters that we will specify as part of the PUT request endpoint/URL by the client.
Step 3 — Deploy the API and Call it!
Check out our S3 Bucket:
Want to learn more about Data Engineering? AWS Cloud?
Check out my series listed below! 🙂
Data Engineering:👇



AWS Cloud:👇


