I have a Java application running on AWS Fargate. Regions.getCurrentRegion() returns null from within an AWS Fargate for security reasons
Is there an alternative way to determine which region the fargate container is running in?
I have a Java application running on AWS Fargate. Regions.getCurrentRegion() returns null from within an AWS Fargate for security reasons
Is there an alternative way to determine which region the fargate container is running in?
In Fargate, the current region is available via the AWS_REGION
environment variable.
If you are using AWS java sdk you can chain AwsRegionProvider
and abstract out logic around region retrieval. If you use a credentials profile, or the environment variable changes, or it eventually becomes available in TaskMetadata you can chain region providers so that you can get region wherever it's available. This also allows you to reuse code that may run on different types of AWS infrastructure.
You would construct an AwsRegionProviderChain
and pass in an instance of each relevant AwsRegionProvider
such as AwsEnvVarOverrideRegionProvider
, AwsProfileRegionProvider
etc.