Optimize images in AWS S3 storage with ImageKit

Here are the steps to optimize images that are present in your AWS S3 bucket with ImageKit

Steps to optimize images from an AWS S3 Bucket using ImageKit

1. You need to grant read access to ImageKit for your AWS S3 bucket(s) with images. This will allow ImageKit to get your images when requested to do so. You can read about IAM policy based S3 access in this article. Note that you need to enable the action “s3:GetObject” as mentioned in the previous article.

2. Once granted access, note down the Access Key and the Secret Key for the user you created in the last step.

3. Log in to your ImageKit dashboard and go to the Integration section. Click on  the “Add Origin” button.

4. In the form that opens up, select “Amazon S3” as the “Origin Type”. You can give this source any “Origin Name”.

5. Provide the bucket name in the “S3 Bucket Name” field.  The images in your S3 bucket could have a fixed prefix (i.e. they appear inside a particular folder). If that is the case, then you can specify the full prefix to your images in the “S3 Bucket Folder” field. If your images are present at the base or root of your S3 bucket then you can enter “/” here.

6. Use the Access Key and the Secret Key for the user you created in step 1 in the “S3 Access Key” and “S3 Secret Key” fields respectively.

7. Click on “Save”.

8. In the “Image URL Patterns” section,  you will find this new source added in “Image Origin preference” list with the “Default URL pattern”.

9. You can either continue to use the “Default URL pattern” or create a new pattern for your S3 images as described here.

10. Note that, ImageKit does not download objects from the S3 storage to optimize images. Whenever you request an image in your S3 bucket, using an ImageKit URL and when the image is not available in ImageKit’s storage, only then will it get the image from the S3 bucket. Image optimization and transformation is done in real time. You can read more about it here.

11. Example –
If the path of the image in your S3 bucket is “/path/to/my/image.jpg”, then the image will be accessible on this path

With default URL pattern


With custom URL pattern


You can read more about the image URL construction here.

Please reach out to us at developer@imagekit.io in case you have any questions or concerns about the above integration or if you want our team to assist you with these changes.