DEV Community

Cover image for Deploy Strapi on AWS with Microtica in 10 minutes
Marija N. for Microtica

Posted on • Originally published at microtica.com

Deploy Strapi on AWS with Microtica in 10 minutes

This article is a step-by-step guide on how to deploy Strapi on your AWS account using Microtica.

Strapi is an open-source headless CMS built with NodeJS. Using Strapi you can easily design and publish your content consumed by your apps via API. Strapi provides a great admin UI portal where you can design your data models, create and manage content.

The benefits of using Microtica for your Strapi projects is the simplicity of setup and low maintenance, while having the infrastructure on your own AWS account. We are following the GitOps and declarative infrastructure approach for stable, more reliable and predictable deployments.

With our approach, Strapi can coexist with your existing AWS infrastructure and you always have the flexibility to extend this setup with additional cloud resources.

Infrastructure ownership
The Strapi infrastructure will be provisioned on your own AWS account. You retain full control over your infrastructure and data while getting all the benefits of infrastructure automation.

What will be provisioned on AWS

Since Microtica deploys on your cloud account, you would expect nothing less than a complete transparency of what resources are going to be provisioned.

Strapi template – Microtica components<br>

Using the Strapi template, we will create a new environment and automatically create a few components in the environment:

  • VPC – VPC, subnets and networking
  • AppRunner – Container infrastructure based on Fargate and application load balancer. This component will run the Strapi project
  • StrapiInfra – Persistent storage, relational databased and S3 storage
  • StrapiApp (optional) – component for your existing Strapi project. If not provided, a standalone Strapi development environment is created

Below is a high-level diagram of the resources that will be provisioned.

Strapi template – cloud resources

Persistent Storage

The Strapi template uses an Amazon EFS file system to store the persistent Strapi files:

  • image uploads – media files storage
  • api folder – only for the standalone setup where you don’t have your source code connected via Git (default). In this guide we will explain how you can deploy your existing Strapi project
  • data folder – store the sqlite data file, if database client is sqlite (default)

The data stored in these folders will persist on subsequent deployments, application restarts or even if you kill the container completely.

Relational Database

The template provisions an RDS MySql database only if the database client is mysql.

Database is encrypted using a custom KMS key. Database password is automatically generated and stored securely in a AWS Secret Manager secret.

Container Environment

By default, the template provisions an AWS Fargate cluster with one container. For production environments we recommend at least two containers running all the time. This will also ensure a zero-downtime deployment.

The Fargate services is exposed via Application Load Balancer. When using custom domain, which is recommended for production, the domain certificate will be attached and SSL termination will happen on this load balancer.

Since we use persistent file storage, all containers share the same file system.

Strapi Logs

The Strapi application logs are stored in a CloudWatch Logs. You can monitor the logs from the Fargate console under tasks. The default log retention is 90 days.

Deploy Strapi Infrastructure

Microtica provides a built-in environment template that provisions the necessary infrastructure to run Strapi on your AWS account in a scalable, secure and reliable way with zero downtime deployment.

To deploy the infrastructure you need to create an environment. Choose Environments under Infrastructure Builder from the main menu and hit on Create Environment.

Enter the environment name and description and choose the Strapi template from the list.

Select Strapi environment template

Cost Optimization
You can optionally enable Cost Optimization for non-production environments. This will stop the RDS instances if you use mysql as database client.

Once the environment deployment finishes, hit on the Quick Deploy button. Since the environment is new, you need to configure the target AWS account where your Strapi infrastructure will be provisioned. Here is a quick guide How to Connect your AWS account.

Once your AWS account is connected and configured in the environment, click again on Quick Deploy to trigger the deployment.

It takes up to 10 mins to create a live Strapi environment.

Once the environment deployment finishes, you can find the access URL in the environment details by expanding the AppRunner component.

Strapi access URL

Configure a Custom Domain and SSL

By default, Strapi will be available on an auto-generated domain via http protocol.

To configure a custom domain you would need to do the following:

  • configure the custom domain
  • configure the SSL certificate
  • add the DNS records in your domain provider

Configure the custom domain

To configure the custom domain, simply enter the custom domain in the AppRunner component DomainName parameter.

Configure the SSL certificate

To create an SSL certificate follow the How to create SSL certificate guide.

Once you have your issued SSL certificate through AWS Certificate Manager you just need to copy the certificate ARN and past it in the AppRunner component CertificateArn parameter.

Add the DNS records in your domain provider

While in the environment details, expand the AppRunner component and copy the value of the CNAME parameter and add it as a CNAME record in your DNS provider.

Strapi CNAME record

Scaling

You can scale your Strapi project vertically and horizontally.

For vertical scaling, update the CPU and Memory configuration in the StrapiInfra component. For horizontal scaling, update the number of desired replicas in the same StrapiInfra component.

Estimated AWS cost

The estimated cost of AWS cloud depends from the configuration of the Strapi infrastructure. Below is the cost estimation breakdown based on different configurations assuming the resources are running all the time:

  • sqlite with one app container (0.25 vCPU and 0.5GB memory) the costs is around $30/month
  • MySql with one app container (0.25 vCPU and 0.5GB memory) the cost would be around $45/month each additional container with the default config is $14/month
  • Additional costs apply for using the AWS EFS for storing media files (~$0.09 GB/month).

You can reduce the cost of your non-production Strapi environments with our Cloud Waste Manager.

Discussion (0)