Search code examples
javakotlinamazon-ecs

Is it possible to check if server is running on ECS Fargate


Currently migrating my server with java/ kotlin from Elastic Beanstalk with EC2 to ECS Fargate. In the application we had the following code to check if the instance is running on AWS or locally:

Regions.getCurrentRegion() != null

This code is sadly only for EC2 instances, so was wondering if there is something similar for ECS Fargate or if we should just remove those checks in our codebase.


Solution

  • To check, inside your code, if the code is running in ECS Fargate you could check for the existence of the ECS_CONTAINER_METADATA_URI_V4 environment variable.