DEV Community

Cover image for How to setup Amazon S3 upload provider in your Strapi app

How to setup Amazon S3 upload provider in your Strapi app

・Updated on ・3 min read

Strapi, by default, stores all files in public/uploads. In a production environment, you definitely would utilize a service, such as AWS Simple Storage Service (S3). Besides that it makes your Strapi app a stateless application according to the Twelve-Factor App methodology.

In this article, we will learn how to setup AWS S3 upload provider in your Strapi app.

Prerequisites :

Step 1 : Install Strapi AWS S3 upload provider
Open your terminal, then run :
yarn add strapi-provider-upload-aws-s3
npm i strapi-provider-upload-aws-s3 --save

Check your package.json if strapi-provider-upload-aws-s3 exists. If so, you have successfully installed Strapi AWS S3 upload provider.

Step 2 : Create plugins.js in config directory
PATH : ./config/plugins.js

module.exports = ({ env }) => ({
 upload: {
   provider: 'aws-s3',
   providerOptions: {
     accessKeyId: env('AWS_ACCESS_KEY_ID'),
     secretAccessKey: env('AWS_ACCESS_SECRET'),
     region: env('AWS_REGION'),
     params: {
       Bucket: env('AWS_BUCKET_NAME'),
        StorageClass: env('AWS_S3_STORAGE_CLASSES') // Configure your Amazon S3 Storage Classes (including this to environment variable is not a must)
     logger: console // Only if you want to `stdout` logs
Enter fullscreen mode Exit fullscreen mode

Alt Text

Please refer to constructor details for complete configuration.

You may be wondering what AWS_S3_STORAGE_CLASSES is. Here are Amazon S3 Storage Classes :
S3 Standard

  • general-purpose storage of frequently accessed data

S3 Intelligent-Tiering

  • data with unknown or changing access patterns

S3 Standard-Infrequent Access (S3 Standard-IA) and S3 One Zone-Infrequent Access (S3 One Zone-IA)

  • for long-lived, but less frequently accessed data

Amazon S3 Glacier (S3 Glacier) and Amazon S3 Glacier Deep Archive (S3 Glacier Deep Archive)

  • for long-term archive and digital preservation.

Read Amazon S3 Storage Classes for more.

Step 3 : Fill in environment variables
In ./config/plugins.js above, we assigned a lot of environment variables. Now it’s time to fill them in.
PATH : .env (root directory of your Strapi app)
Alt Text

How do I gain my AWS security credentials ?
Simply sign in to the AWS management console, then open the dropdown menu. Select My Security Credentials.
Alt Text

After that you will see a page like this :
Alt Text

Learn more how to gain your AWS security credentials.

Great! Everything is set, next you can start your Strapi app and upload files. Your files will be stored in AWS S3.

Thank you for reading, hope you have a great day today!

Connect with me :
LinkedIn - kevinadhiguna
Github - kevinadhiguna

References :

Discussion (2)

csarigumba profile image
Cedric Sarigumba

Is it possible to use IAM role instead of IAM user access keys?

44db profile image
Yannis Kassotis

Which permissions are needed to use the provider?