Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Fargate hostname not doable?

I am trying to set up a simple app. It is dragged from https://budgetapp.docsapp.io/ and meant to be working somewhere in public. My task is to deploy it in most automate way and expose metrics of java machine to the public (remote jConsole). Eventually, it should be stood up in around 15 exact copies.

For this task I chose AWS Fargate. It sets up the app beautifully, it gives me back the Metrics on admin port (it is deployed by Dropwizard). What I struggle with is monitoring. It should be real live and showing at least CPU and mem usage. I am able to do it locally on docker, but Fargate is missing one crucial thing. Setting up hostname for deployed task.

Error that I am getting: Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: 578463faab0f: 578463faab0f: System error. It is due to missing entry in /etc/hosts file with container's uname -n. It seems like I cannot set it up! Is this possible to be done somehow?

I am running my java service like this: java -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=127.0.0.1 -Djava.rmi.server.useLocalHostname=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=5000 -Dcom.sun.management.jmxremote.rmi.port=5000 -jar budgetapp.jar server config.yml

I am happy to take any advice!

like image 897
agat90 Avatar asked Mar 31 '18 21:03

agat90


Video Answer


2 Answers

This is a known issue in the ecs agent. Have you tried this as a workaround:

echo "$(ip a | grep -A2 eth1 | grep inet | awk '{print $2}' | sed 's#/.*##g' ) $(hostname)" >> /etc/hosts

You can grab the ip and modify /etc/host during the entry point in your container.

I believe there is an ecs agent fix on its way, but I cannot find the issue on GitHub.

like image 125
Roy Kachouh Avatar answered Sep 28 '22 10:09

Roy Kachouh


I ran into the same issue on ECS Fargate, with code that worked fine in docker and in CI/CD pipeline. I did not yet have a bootstrap script, so it was a little work to integrate Roy's solution.

Here's what worked for me:

  1. Create a ecs_bootloader.sh shell script into a directory which was already being copied into the image (bin in my case):
#!/bin/bash

echo "$(ip a | grep -A2 eth1 | grep inet | awk '{print $2}' | sed 's#/.*##g' ) $(hostname)" >> /etc/hosts

#My command here:
python bin/run_all.py

Modified my ECS task definition, changing ENTRYPOINT and command to:

ENTRYPOINT: bin/ecs_bootstrap.sh
COMMAND:    bin/run_all.py

NOTES:

  • This could be improved by calling COMMAND from the ecs_bootstrap.sh script. (Currently COMMAND is ignored by the bootstrap script.)
  • Because I was already copying the bin folder to the container, I did not have to modify my Dockerfile.
like image 22
aaronsteers Avatar answered Sep 28 '22 10:09

aaronsteers