Migrating media assets from Cloudinary to AWS S3 using Strapi can significantly improve storage flexibility, cost efficiency, and integration with other AWS services. This guide provides a comprehensive, step-by-step approach to seamlessly transition media files while ensuring minimal downtime and preserving metadata.
Why Migrate from Cloudinary to AWS S3?
Cloudinary is a robust media management platform, but AWS S3 offers more cost-effective, scalable, and customizable storage options, especially for projects requiring deeper integration with AWS tools like Lambda, CloudFront, and IAM policies.
Prerequisites
Before starting the migration process, ensure the following:
- AWS S3 Bucket: Created and configured with appropriate permissions.
- AWS IAM User: Access keys with PutObject and GetObject permissions for the S3 bucket.
- Strapi Installation: A working Strapi project with a properly configured database.
- Cloudinary API Keys: Access to retrieve existing media files.
Step 1: Export Media from Cloudinary
- Log in to Cloudinary and navigate to the Media Library.
- Use the Cloudinary API or bulk export feature to download all assets.
- curl -X GET ‘https://res.cloudinary.com/<cloud_name>/image/list.json’ -u ‘<API_KEY>:<API_SECRET>’
- Save the downloaded media locally before uploading to AWS S3.
Step 2: Configure AWS S3 for Strapi
- Create an S3 bucket in AWS.
- Configure CORS policies to allow Strapi to interact with the bucket.
- Set up an IAM user with the following permissions:
{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“s3:PutObject”,
“s3:GetObject”,
“s3:ListBucket”
],
“Resource”: “arn:aws:s3:::your-bucket-name/*”
}
]
}
- Obtain the Access Key ID and Secret Access Key for authentication.
Step 3: Install and Configure Strapi S3 Plugin
- Install the AWS S3 upload provider for Strapi:
- npm install strapi-provider-upload-aws-s3
- Modify the config/plugins.js file in the Strapi project:
module.exports = ({ env }) => ({
upload: {
provider: ‘aws-s3’,
providerOptions: {
accessKeyId: env(‘AWS_ACCESS_KEY_ID’),
secretAccessKey: env(‘AWS_SECRET_ACCESS_KEY’),
region: env(‘AWS_REGION’),
params: {
Bucket: env(‘AWS_BUCKET_NAME’),
},
},
},
});
- Add the corresponding environment variables to .env:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=your-region
- AWS_BUCKET_NAME=your-bucket-name
- Restart Strapi to apply the changes.
Step 4: Upload Media to AWS S3
- Write a script or use the AWS CLI to upload exported Cloudinary files:
- aws s3 cp /local/path s3://your-bucket-name –recursive
- Verify that the files appear in the S3 bucket.
- Update existing database records in Strapi to reflect new S3 URLs.
Step 5: Test and Validate Migration
- Open the Strapi Admin Panel and confirm media files load correctly.
- Check AWS S3 to ensure the uploaded files are accessible.
- Test integrations with front-end applications or CMS to confirm the successful migration.
Conclusion
Migrating media from Cloudinary to AWS S3 using Strapi is a straightforward process that enhances cost efficiency and storage control. By following these steps, developers can ensure a smooth transition while maintaining high performance and scalability for media assets.