Search code examples
amazon-web-servicesamazon-ecsaws-fargate

Are there any Env variables automatically set on fargate tasks


I’d like to be able to detect if my code is running on a fargate task (as opposed to on an EC2 instance) and it would be ideal if I could get the fargate task ID from an env var.

I would then use this info for logging and config.

Many CI environments set some env vars which allow me to detect if my code is in CI.

Does AWS do anything similar?


Solution

  • You can query the ECS metadata service for the LaunchType value, which will either be EC2 or FARGATE.