How to deploy Docker container to AWS ECS

This post complements my video on How to deploy Docker container to AWS ECS. If you haven’t seen my post on Dockerizing Microservices, I would highly recommend reading it first. This post along with the video covers the following topics.

  • Docker setup
  • Creating IAM user for ECR
  • ECS Cluster
  • Elastic Container Registry
  • Task Definition
  • Service

First log into AWS console, click on ECS (Elastic Container Service) and click on Repository to create a Docker repository. Once, the repo is created click on View Push Commands on the top right, you should see a list of commands as below.

If you have not created an IAM user, watch the video to create an IAM user with proper permissions. Type ‘aws configure’ on your terminal and log in using access key and the secret access key as below.

Then type in the following commands, as listed. These commands will be different and specific to your image and repository.

This completes and pushing your image to ECS. Please proceed to the video to complete the rest.


AWS migration and DB performance with Spring Microservices

We recently moved a few applications to AWS cloud and immediately started noticing a significant drop in performance.  This was happening for the applications that were being developed locally on-premise, and access Oracle database on the cloud.  Performance decreased by many folds.  One of the applications that used to take 5 minutes to process 35 million records, was taking 3 hours.

I excepted a little bit performance hit, but not 36 times slower. First, I checked all our recent commits, to see if any of the recent changes were causing the issue, but I didn’t notice anything significant.  Then, I checked SQL execution plan and fine-tuned SQL created indexes on the key columns. This didn’t make any difference at all.  I also tried tracing network and traffic but didn’t see anything important.

Adding to the confusion, when I tried running the same queries as in the application with SQL clients like SqlPlus, Toad etc. selects ran in seconds. This ruled out the possibility of something wrong with the SQL. To narrow it down, I created a very simple microservice that ran same queries without any data processing, but it took hours to run. This pointed to the fact that, even though SQL itself was running fast, once it was used in an application, something was going wrong.

After fiddling with different configurations, I started noticing immediate improvements in performance, as soon as I added setFetchSize to Spring JdbcTemplate and tuned it, the performance came back to before migration levels, from 3 hours to 5 minutes.  Here is the code in Scala, depending on your configuration your fetch size, may be different.

If you are using Spring’s NamedParameterJdbcTemplate, configure JdbcTemplate as above and pass it to NamedParameterJdbcTemplat as a constructor arg.