【问题标题】:java springboot app on local container fails to access aws本地容器上的 java springboot 应用程序无法访问 aws
【发布时间】:2020-06-18 12:18:10
【问题描述】:

在我的 java 应用程序中,我正在创建以下 S3 客户端:

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();

我的码头文件:

FROM openjdk:11.0.7-jre-slim
EXPOSE 8080
COPY target/myjar.jar /usr/app/
WORKDIR /usr/app
ENTRYPOINT ["java", "-jar", "myjar.jar"]

我将我的 java 应用程序部署到本地容器并使用以下运行命令:

$ docker run my-image-name --net="host" -e AWS_ACCESS_KEY_ID=XXXXXX -e AWS_SECRET_ACCESS_KEY=XXXXXX -e AWS_DEFAULT_REGION=eu-central-1

但是当我的 springboot 应用程序启动时,我在 s3Client 初始化时遇到异常:

com.amazonaws.SdkClientException: Failed to connect to service endpoint:
......
Caused by: java.net.ConnectException: Connection refused (Connection refused)
.....
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyService': Invocation of init method failed; nested exception is 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.

Caused by: 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.

如您所见,我传递了环境变量 AWS_DEFAULT_REGION(也尝试过 AWS_REGION),但仍然出现此错误。

我正在使用以下 sdk 版本:

<aws-java-sdk-core.version>1.11.800</aws-java-sdk-core.version>

当我从 inteliJ 启动应用程序时,一切正常 gr8,因为我的配置和凭据是在 .aws 目录中配置的。

也许我需要在外面公开任何端口?

【问题讨论】:

  • 试试-e var1=1 var2=2 ...
  • 没有秘密访问密钥?仍然得到完全相同的错误
  • 不,只需将所有参数合并到一个 -e 选项中
  • 完成了,得到了同样的错误
  • hm,你可以用docker run ... -e ... envbaeldung.com/ops/docker-container-environment-variables检查哪些变量存在

标签: java spring amazon-web-services docker


【解决方案1】:

我决定启动一个 ec2 节点并将我的代码部署到那里进行测试。不知道为什么将区域 env 传递给本地容器时不够。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    相关资源
    最近更新 更多