aws / aws/containers-roadmap

[ECS] [request] Passing container instance environment variables to agent

Open
#1,548 7 comments 3 reactions 0 assignees View on GitHub
ECS Proposed
Dominant language
Shell
Stars
5.4k
Forks
334
PR merge metrics
No merged PRs in 30d

Description

### Summary
I want to inject a system-level environment variable `FOO` exported on all cluster container instances into ECS tasks. This is a separate environment variable being used as a required identifier separate from app configuration pulled using parameter store. What's the recommended way to do this?

### Description
`FOO` is exported on the container instance in `/etc/environment`. Here are a few routes I've considered:

1. Adding value to `/etc/ecs/ecs.config`.
2. Creating a separate configuration file in `/etc/ecs` with the value.
3. Passing `FOO` directly when the `ecs-agent` is [started](https://github.com/aws/amazon-ecs-init):

```
docker run --name ecs-agent \
--detach=true \
--restart=on-failure:10 \
--volume=/var/run/docker.sock:/var/run/docker.sock \
--volume=/var/log/ecs:/log \
--volume=/var/lib/ecs/data:/data \
--net=host \
--env-file=/etc/ecs/ecs.config \
--env=ECS_LOGFILE=/log/ecs-agent.log \
--env=ECS_DATADIR=/data/ \
--env=ECS_ENABLE_TASK_IAM_ROLE=true \
--env=ECS_ENABLE_TASK_IAM_ROLE_NETWORK_HOST=true \
--env=FOO=${FOO} # PASSING NEW ENV VAR
amazon/amazon-ecs-agent:latest
```

### Expected Behavior
Each task in the ECS service has access to `FOO` as an environment variable.

### Observed Behavior
With the current configuration, `FOO` is available on all container instances shell environments but isn't passed through to tasks. This is expected because the `ecs-agent` is isolated from the host environment.

### Environment Details
Docker version: `Docker version 19.03.13-ce, build 4484c46`
Running ECS Optimized Image

### Supporting Log Snippets
I can't post logs here.

Contributor guide

Open the contributing guide

Research direction

Start with the ECS agent startup command and the `/etc/ecs/ecs.config` and `/etc/environment` paths described in the issue. Determine the supported way to propagate a container-instance variable into ECS tasks; done means every task in the ECS service receives `FOO` while application configuration remains separate.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker
Domain
cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.