Strapi on AWS with ECR and ECS

Strapi on AWS with ECR and ECS

·

3 min read

Running a Strapi on AWS have many different way. This is a simple guide to play with the ECR and ECS service. Since different cases may have different setting, the following is only consider to use the lowest price and setup as possible to test the case and this setup is out of the free tier.

Setting up AWS ECR

Setup AWS CLI Config

Set IAM user access id and secret key (and default-region) to aws-cli by calling following command.

aws configure

Goto ECR portal create a private or public repository. Click the repo you just created and see there is a "view push commands" button.

Untitled.png

Following all the step, your images should be successfully uploaded.

Untitled 1.png

Setting up AWS ECS

Create Cluster

  1. Select the EC2 Linux + Networking one
  2. Fill the Cluster name Fill the EC2 instance type by your needs Fill the Number of instances by your needs Fill EC2 Ami Id, you may either use the recommended Amazon Linux 2 AMI which is ECS-optimised or create any instance and do the ECS config yourself. Setup the security group for which ports are allowed Choose the IAM role as ecsInstanceRole, if you are not created it yet, you may leave it and ECS will automatically create it for you. Other setting based on your own load balancing setup, if nothing special you may proceed it.
  3. After created the cluster, goto the cluster main page and click ECS Instances. You can check the CPU and memory resource your instance is actually have.

Screenshot_2021-01-15_at_6.56.12_PM.png

Create Task Definitions

  1. Select EC2 one
  2. Fill Task Definition Name Goto Task size, fill in the Task memory and Task CPU. Please aware you can not exceed the available memory and CPU that you previously checked. Screenshot_2021-01-15_at_6.59.43_PM.png
  3. Click Add container. Fill Container name and Image src. Fill the Memory Limits, do not exceed the Task memory you previously selected. Fill the Port mappings, eg Strapi will use 1337 in default, you may set 80, 1337 tcp Fill the CPU units, do not exceed the Task CPU you previously selected. Screenshot_2021-01-15_at_7.06.28_PM.png
  4. If no warning about the resource, you may click 'Create'.

Create Service

  1. To launch a web service, goto the cluster main page click 'Create' under the Service tab.
  2. Fill the task definition you created. Fill the Service name. Fill the number of tasks is running in this service. If no specific load-balance setting, you may just proceed. Screenshot_2021-01-14_at_6.46.34_PM.png
  3. Wait for a moment for the service and the task to launch. If there is problem regarding the task, you may check it at the 'Tasks' Tab in the cluster main page. Warning message will be shown on the top.