Debug Docker Container In Amazon ECS

Dennis Brysiuk
NEW IT Engineering
Published in
4 min readSep 17, 2021

Motivation

After switching from standard on-prem applications to cloud hosted applications, I quickly realized that local debugging is not so common.

Viewed objectively, it is understandable. By outsourcing the resources to the cloud, is the accessibility and internal configuration to them is quite difficult or even impossible. Nevertheless there should be a “simple” solution for a hot deploy of an application in the cloud.

AWS Toolkit

After a short research I found the Open Source Plug-In AWS Toolkit for JetBrains. This plugin allows you to create, debug and deploy applications from the IDE on AWS.

Setup

Installation and configuration is pretty easy. In this example I show how to install AWS Toolkit in IntelliJ IDEA and how to configure local debug for an application running on AWS ECS using Fargate.

Installation

Go to the Settings in ItelliJ IDEA (STRG+ALT+S) then choose Plugins and make sure that you are in Marketplace section and then search for AWS Toolkit and press install.

In my case it is already installed.

AWS Credentials

Setup your AWS account profile and credential information located in homepath/.aws/configand homepath/.aws/credentials or directly via AWS Toolkit settings.

To create, read, update and delete the resources from IDE it is required to create a new Role in AWS IAM with the following AmazonSSMManagedInstanceCore policies attached.

Run Debug Cluster

  • Go to AWS Explorer in IntelliJ IDEA and search for the ECS cluster that you want to debug.
  • Press right click on that service and execute Enable Cloud Debugging
  • Select the previously created AWS role and confirm this

This process will take a while. In the background, the entire Elastic Container Service will be cloned. After it is done, the icon from that service in AWS Explorer will change to a “bug”.

Run Remote Debug

When the debug cluster is running, all you have to do is right-click on the service and select run debug.

At the first time you have to configure the run configuration of the debugger. There are many possible settings but only 3 are required:

  1. Start Command (command that executed from docker to start your application)
  2. Artifacts Mappings (can be taken over from dockerfile)
  3. Port Mappings (freely selectable)

Common Issues

Unfortunately is this Plug-In still in beta since many years and only one person can debug at the same time :(

Here are a few tips and solutions that have helped me:

  • Before close you IDE disable cloud debugging cluster
  • Apply run configuration after entering all settings — not after each setting
  • If you cannot start or stop cloud debugging cluster because the role or session is already used, then go to the AWS Console and delete the S3 Bucket created from AWS Toolkit Plug-In
  • After changing AWS config or credentials file restart your IDE

Summary

Incredibly in 5 minutes you can do local debug and hot deployment in an CLOUD and this is just one function of the AWS Toolkit Plug-In. This saved my colleagues and me a lot of stress and time :)

Try it out, explore it and have fun.

--

--