Zend certified PHP/Magento developer

AWS s3 for images – how to configure IAM?

I’m using Magento 2.4.3-p1 Community running on AWS EC2. I’m moving the images to live on s3 storage, following this guide: https://devdocs.magento.com/guides/v2.4/config-guide/remote-storage/config-remote-storage-aws-s3.html

I have setup an IAM user that has GetObject, GetObjectAcl, PutObject and PutObjectAcl permissions in it’s role, restricted by resource to the specific bucket I’m storing images in.

The Magento guide says “Set up AWS IAM roles. Alternatively, generate access and secret keys.” but doesn’t give any further details. It mentions if you use access keys, you need to use the ngx_aws_auth module, which I’d like to avoid if possible (it’s not clear how to install it, and if I can avoid another dependency, that’s good).

The problem
So far, images can be uploaded to s3 via the admin area (or via the migrate command that Magento provides). However, when I try to view the images, their URLs are redirected to a XML error from AWS stating:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint`

I’ve changed the nginx config as shown so that set $bucket "my-bucket-name" is set. It’s not clear if that’s supposed to include the region or some other data.

Can anyone else clarify how to setup the IAM role so it doesn’t need auth for Magento to access the s3 images? I may be being daft, but it feels the Magento guide is missing a good chunk of information that’s required to actually get it working!