Serving resized S3 images on the fly

#7 Talking to S3

Let’s retrieve images from the AWS S3 bucket

.com software
3 min readSep 1, 2022

--

Photo by ANIRUDH on Unsplash

If you didn’t notice — this is part of a series

Our MVP application is done. All the abstractions are complete. It’s time to start talking to S3. To do that all we need is the new image source. Until this moment I was using only a mocked source.

Installing the library

The beauty of interfaces is you can easily switch functionalities without affecting the application. First, I’ll need a library to talk to AWS. I’ll go for the official aws/aws-sdk-php library, no bloated bundles required:

composer require aws/aws-sdk-php

Configuring the client

To have a read-only access to the S3 bucket with source images, I needed to make some modifications in the AWS management console. I created an IAM policy with access to the GetObject action on the S3 bucket containing images:

I’ve also created a user with programmatic access and the policy above attached to it. This way I was able to obtain the…

--

--

.com software

Father • PHP developer • entrepreneur • working for a €1bn unicorn startup as a backend engineer >>> https://bit.ly/dotcom-software