Create ECS task definition for Rails Docker image (Rails and Sidekiq)

This article is the continuation of Rails + Sidekiq + Docker Application for AWS (ECS, ECR, RDS, Codepipeline and more) complete series. For better understating, please start from the beginning of the series.

AWS ECS Task Definition

AWS ECS task is a bit similar to Docker compose. task definition has the ECR Docker image and container along with Environment variables. Ultimately, the task will be deployed inside ECS Cluster which we will create later.

We will create two task definitions (Rails and Sidekiq) in this article.

Task Definition for Rails

We will need the following credentials while creating the task

  • Database credentials from RDS
    • DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT, DB_HOST
  • Redis endpoint from AWS elastic cache
    • REDIS_HOST, REDIS_PORT

Open ECS from AWS service tab and select Task Definitions, click on Create new Task Definition

Put the ECR image version we have pushed earlier in the Image* field.

We have added port mapping 0 -> 3000. Any port from outside world will be mapped to container’s port 3000

We have provided all the credentials required for our application to perform. Apart from Environment variables, we have also provided the command our container should run puma, -C, config/puma.rb, -p, 3000

Make sure that you tick CloudWatch Logs, otherwise it can be really difficult to troubleshoot the task / conainer if it fails for any reason.

Task Definition for Sidekiq

We will create a task definition again. Everything will be almost the same expect task name, container name and execution command inside the container.

we will call our new task rails-application-sidekiq-task

Name for the container will be sidekiq with just few adjustments

We’re not doing any port mappings for this container, since the purpose of this container to run sidekiq, it does not require any contact from outside world

We will provide the all Environment variables like the web task. the command for this container will be sidekiq

Written by

Leave a Reply

Your email address will not be published. Required fields are marked *