Serving resized S3 images on the fly
#7 Talking to S3
Let’s retrieve images from the AWS S3 bucket
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…