Create a Headless CMS in a few hours with Strapi

1. Setup a local Strapi

Setting up a local version is really simple, especially before you try to connect with AWS services. Thanks to Strapi’s online documentation, you can set up a project easily.

npx create-strapi-app@latest my-project--After initializing the project,you can run the follow command to start your instancenpm run develop

2. Set up AWS S3 as the content repository

Strapi uses the default /public/uploads folder as a content repository. This is not ideal in a cloud-native environment. In the next step, I will set up an AWS S3 bucket and configure Strapi to connect to it as the content repository

2.a Create S3 bucket in AWS

I will skip the steps here. You can find many useful online documents about this. You may follow the steps provided by Strapi to configure S3 and link it up with your Stapi. Strapi set up S3 as an alternative Upload provider.

npm install strapi-provider-upload-aws-s3
modulePath = require.resolve(`strapi-provider-upload-${providerName}`);

2.c create an access key in AWS

Please follow online instruction to create your access key. You can created in AWS IAM Access Key management module. Remember your Key ID and secret

2.d configure Strapi

Create a file named plugins.js if it does not exist already

module.exports = ({ env }) => ({upload: {config: {provider: ‘aws-s3-private’,providerOptions: {accessKeyId: env(‘AWS_ACCESS_KEY_ID’),secretAccessKey: env(‘AWS_ACCESS_SECRET’),region: env(‘AWS_REGION’),params: {Bucket: env(‘AWS_BUCKET_NAME’),},},},}});
// AWS S3AWS_ACCESS_KEY_ID=yourkeyAWS_ACCESS_SECRET=yoursecretAWS_REGION=yourAWSregionAWS_BUCKET_NAME=yourAWSS3bucketName

3. Setup AWS RDS as backend DB

By default, Strapi creates a local SQLite database for various purposes. I’d like to set up a separate database instance to replace SQLite. I choose to use AWS RDS PostgreSQL in my testing.

3.b configure Strapi to connect to RDS

Similar to S3 configuration, you need to add config details in /config/database.js

module.exports = ({ env }) => ({connection: {client: “postgres”,connection: {host: env(“DATABASE_HOST”, env(‘DATABASE_HOST’)),port: env.int(“DATABASE_PORT”, env(‘DATABASE_PORT’)),database: env(“DATABASE_NAME”, env(‘DATABASE_NAME’)),user: env(“DATABASE_USERNAME”, env(‘DATABASE_USERNAME’)),password: env(“DATABASE_PASSWORD”, env(‘DATABASE_PASSWORD’)),},useNullAsDefault: true,},});

4. Migrate Strapi to AWS

Running Strapi on local is not an option for production use. You can migrate your Strapi server to AWS EC2 or EKS or ECS, etc.

4.a check in your code to a git server — I used Bitbucket

4.b install Node on EC2

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash. ~/.nvm/nvm.shnvm install 12.22.10

4.c install git on EC2

sudo yum install git -y

4.d clone your code from your git server

Git clone https://yourgitrepo

4.e install packages in your project

Go to your project folder and run “npm install”

4.f fix the private S3 connection issue as in step 2.b

4.g create .env file in your EC2 Strapi folder

normally .env is not and should not be checked into your git repo. So you should create it in your EC2 Strapi project folder.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aaron Yu

Aaron Yu

44 Followers

I am not a coder, but I like solving problems programmably