强制AWS库从Docker集群内部的环境中获取区域

强制AWS库从Docker集群内部的环境中获取区域

本文介绍了强制AWS库从Docker集群内部的环境中获取区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试在桌面上的Docker容器中运行的Java应用.如果直接从命令行执行该应用程序,则该应用程序运行良好,但是当我尝试在桌面上的Docker容器中运行该应用程序时,该应用程序将失败.错误输出显示该库正在请求区域信息,然后由于以下错误而失败:

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.)

推荐答案

AWS的实现与此不一致,因为有时需要AWS_DEFAULT_REGION,而有时需要AWS_REGION.对于Java的AWS API,请使用AWS_REGION. (同时指定两者都可以在所有情况下正常工作.)

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)在对类似问题的评论中透露了这个答案.]

[h/t John Camerin who revealed this answer in comments on similar questions.]

cf. 44151982 36354423 Github aws/aws-sdk-go#2103

这篇关于强制AWS库从Docker集群内部的环境中获取区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 23:10