在我的Java应用程序中,我正在创建以下S3客户端:
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().build();
我的docker文件:
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启动应用程序时,由于我的配置和凭据是在.aws目录中配置的,因此所有功能都可以正常运行。
也许我需要在外部暴露任何端口?
答案 0 :(得分:0)
我决定启动一个ec2节点并将代码部署到那里进行测试。不知道为什么将区域env传递给本地容器时不够用。