How to automatically store images on AWS-S3?

This guide explains how to configure your Sylius 2.x store to automatically upload and store images (such as product images) on Amazon Web Services (AWS) S3. Using S3 storage reduces server load, improves performance, and provides scalability for your images.

Prerequisites

Make sure you have:

  • A working Sylius 2.x project

  • An AWS account with S3 access

  • Familiarity with Symfony configuration


1. IAM Setup & S3 Configuration

1.1 Create an IAM User for S3

  1. Go to IAM > Users > Add user

  2. Set the User name, e.g., sylius-s3-media

  3. Enable Programmatic access

  4. Click Next: Permissions

  5. Choose Attach policies directly β†’ click Create policy

  6. Choose the JSON tab and paste:

  1. Name and create the policy (e.g., SyliusS3AccessPolicy)

  2. Return to user creation β†’ attach the policy β†’ finish and download credentials

1.2 Configure your AWS CLI client

circle-exclamation

Enter your:

  • AWS Access Key ID

  • AWS Secret Access Key

  • Default region (e.g., eu-west-3)

  • Default output format (e.g., json)

circle-check

1.3 Create an S3 Bucket

After sucessful setup of access keys you will be able to create the bucket

circle-check

1.4 Configure Bucket Policy (for public read access)


2. Symfony & Flysystem Configuration

Install Required Packages

Add AWS env variables

Add these variables to your .env file:

Configure AWS Client

Create config/services.yaml:

Configure Flysystem

circle-exclamation

Critical Note


3. LiipImagineBundle Configuration

Update config/packages/liip_imagine.yaml:

4. Testing

Clear Cache

Test the configuration

Run the Sylius fixtures to check if the images are correctly loaded


Testing the Configuration using AWS CLI

Test S3 Upload

Test Image Generation

Create a test command to verify image processing:

Run the test:


Debugging Commands


Verify Your Setup

  • Log in to your AWS console and open your S3 bucket.

  • Check if the uploaded images appear under the configured folder (media/image).


Troubleshooting

  • Region Issues: Confirm your bucket region matches your AWS configuration.

  • Images Not Uploading: Ensure environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET) are correctly defined.


Further Reading

Congratulations! You've successfully configured automatic image storage with AWS S3 in your Sylius application.

Last updated

Was this helpful?