0

I have a docker compose configuration that I'm deploying in an ECS Fargate cluster. The tasks are configured with assign_public_ip: ENABLED, and they seem to be getting a public IP, but I'm struggling to figure out how to retrieve the IP. The service I'm running must know its public IP or hostname to work properly. There is an env var called ECS_CONTAINER_METADATA_URI that is supposed to point to the instance metadata, but it seems to be empty when I curl it. Here is the output of env:

AGENT_NAME=Certifier
APP_ROOT=
AWS_DEFAULT_REGION=us-west-2
AWS_EXECUTION_ENV=AWS_ECS_FARGATE
AWS_REGION=us-west-2
CARGO_HOME=/usr/local/cargo
DESCRIPTION=von-image provides a consistent base image for running VON python web components. Based on Ubuntu bionic, this image includes Python 3.6.9, indy-sdk, and supporting Python libraries.
ECS_CONTAINER_METADATA_URI=http://169.254.170.2/v3/1bbe943c-8fd9-40bf-8aed-477ee26eae69
HOME=/home/indy
HOSTNAME=ip-10-0-1-15.us-west-2.compute.internal
LANG=C.UTF-8
LC_ALL=C.UTF-8
LD_LIBRARY_PATH=/home/indy/.local/lib
LIBINDY_DIR=/home/indy/.local/lib
LIBSOVTOKEN=/home/indy/libsovtoken-1.0.1/libsovtoken/target/debug/libsovtoken.so
PATH=/usr/local/cargo/bin:/home/indy/.local/bin:/home/indy/bin:/home/indy/.pyenv/shims:/home/indy/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIP_NO_CACHE_DIR=off
PORT=4000
PWD=/home/indy
PYENV_ROOT=/home/indy/.pyenv
PYTHONIOENCODING=UTF-8
PYTHONUNBUFFERED=1
PYTHON_VERSION=3.6.9
RUSTUP_HOME=/usr/local/rustup
RUST_LOG=warning
RUST_VERSION=1.41.1
SHELL=/bin/bash
SHLVL=1
SUMMARY=von-image including Python 3.6.9 and indy-sdk
_=/usr/bin/env

When I actually attempt to download this metadata, however, it appears to be empty. The following lines in my startup script:

curl "$ECS_CONTAINER_METADATA_URI/task" -o "$HOME/results.json"
cat "$HOME/results.json"

produce the following output:

+ curl http://169.254.170.2/v3/6f818f2c-6a01-4975-b937-6b5658eac7e2/task -o /home/indy/results.json
Dload Upload Total Spent Left Speed
% Total % Received % Xferd Average Speed Time Time Time Current
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
0 100 4112 0 4112 0 0 1003k 0 --:--:-- --:--:-- --:--:-- 1003k
+ cat /home/indy/results.json

The results are empty. I'm concerned that maybe there is a permissions issue, but unsure how to verify this or fix it. Thanks in advance for your help.

1 Answer 1

1

It looks as if you're querying the V3 API, but /task is a V4 method. Try using this environment variable instead: ${ECS_CONTAINER_METADATA_URI_V4}

If that isn't set, you're probably not launching tasks using the most recent version of the Fargate platform. You could either fix that, or use a V3-compatible method as described here: https://docs.aws.amazon.com/AmazonECS/latest/userguide/task-metadata-endpoint-v3-fargate.html

2
  • Thanks! That env var is not available, but even when I request the URI by itself, I don't get any response. I'm following this guide: docs.aws.amazon.com/AmazonECS/latest/developerguide/…. Not seeing anything obvious that would be triggering V3 instead of V4.
    – cayblood
    Apr 12, 2020 at 23:38
  • As I look at this more closely, it seems that the default platformVersion is still 1.3.0, not 1.4.0. I think I may need to manually specify this when creating the cluster, although I'm still trying to figure out how.
    – cayblood
    Apr 13, 2020 at 5:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .