问题
I’m trying to test a Java app running in a docker container on my desktop. The app runs fine if I execute it directly from my command line, but it fails when I try to run it inside a Docker container on my desktop. The error output shows that the library is requesting region information, then failing with this error:
com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.
I am providing the region as an environment variable:
AWS_DEFAULT_REGION=us-east-2
If I hard-code the region, it works fine. (The library is successfully extracting the credentials from environment variables.)
回答1:
You need to set AWS_REGION
, not AWS_DEFAULT_REGION
. Default Region Provider Chain
回答2:
AWS is inconsistent in its implementation for this, as sometimes AWS_DEFAULT_REGION
is required, other times AWS_REGION
is required. For the AWS API for Java, use AWS_REGION
. (Specify both to work in all situations.)
[h/t John Camerin who revealed this answer in comments on similar questions.]
cf. 44151982, 36354423, Github aws/aws-sdk-go#2103
来源:https://stackoverflow.com/questions/60532462/force-aws-library-to-obtain-region-from-environment-inside-docker-cluster