英文:
AWS SDK 1.11.844 is throwing Continuously ERROR while connecting to Kinesis Stream
问题
我正在使用Spring Cloud Data Stream和Kinesis Spring Binder来连接Kinesis。默认情况下,它使用aws-sdk 1.11.415,无法在Kubernetes环境(AWS EKS)中用于假定角色(Assumed Role)部署。我已经找出我需要将库升级到aws-sdk 1.11.844,以支持基于WebIdentityToken的凭证提供程序。在Kubernetes中,这是有效的。现在从我的本地机器尝试通过启用实例配置文件(禁用基于WebIdentityToken的流程)连接到Kinesis,但始终抛出以下错误,无法连接。当我注释掉此升级库时,它会回到正常工作的aws-sdk 1.11.415。但我需要升级为基于WebIdentityToken的凭证提供程序。
如果有人有任何解决方案,请帮助我。我不能切换到AWS SDKV2,因为Spring Binder不支持它。任何其他解决方案都将是有帮助的。
com.amazonaws.SdkClientException: 无法连接到服务终端点:
在 com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) ~[aws-java-sdk-core-1.11.844.jar:?]
在 com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:70) ~[aws-java-sdk-core-1.11.844.jar:?]
在 com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.readResource(InstanceMetadataServiceResourceFetcher.java:75) ~[aws-java-sdk-core-1.11.844.jar:?]
在 com.amazonaws.internal.EC2ResourceFetcher.readResource(EC2ResourceFetcher.java:66) ~[aws-java-sdk-core-1.11.844.jar:?]
在 com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:402) ~[aws-java-sdk-core-1.11.844.jar:?]
在 com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:371) ~[aws-java-sdk-core-1.11.844.jar:?]
在 org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment(AwsCloudEnvironmentCheckUtils.java:38) ~[spring-cloud-aws-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
...
在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
在 com.baxter.renal.app.s3.poc.CAPDTreatmentUploadApplication.main(CAPDTreatmentUploadApplication.java:22) [classes/:?]
引起:java.net.SocketTimeoutException: 连接超时
在 java.net.PlainSocketImpl.waitForConnect(Native Method) ~[?:?]
在 java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107) ~[?:?]
英文:
I am Using Spring Cloud Data Stream and Kinesis Spring Binder to connect to Kinesis: <https://github.com/spring-cloud/spring-cloud-stream-binder-aws-kinesis/blob/master/spring-cloud-stream-binder-kinesis-docs/src/main/asciidoc/overview.adoc>
By default, it uses aws-sdk 1.11.415 and which can't be used for Assumed Role while deploying in Kubernetes environment (AWS EKS). I have figured out that I need to upgrade the library to aws-sdk 1.11.844 to support the WebIdentityToken based credential provider. This is working in Kubernetes. Now from my local machine, I am trying to connect to Kinesis by enabling instance profile (disabling the WebIdentityToken based flow), it keeps on throwing below error and not connecting. when I comment this upgraded library it goes back to aws-sdk 1.11.415 which is working as expected. But I need to upgrade this for WebIdentityToken based credential provider.
Please help me if anybody having any solution for this. I can't change to AWS SDKV2 as Spring Binder will not support that. Any other solution will be helpful.
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) ~[aws-java-sdk-core-1.11.844.jar:?]
at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:70) ~[aws-java-sdk-core-1.11.844.jar:?]
at com.amazonaws.internal.InstanceMetadataServiceResourceFetcher.readResource(InstanceMetadataServiceResourceFetcher.java:75) ~[aws-java-sdk-core-1.11.844.jar:?]
at com.amazonaws.internal.EC2ResourceFetcher.readResource(EC2ResourceFetcher.java:66) ~[aws-java-sdk-core-1.11.844.jar:?]
at com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:402) ~[aws-java-sdk-core-1.11.844.jar:?]
at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:371) ~[aws-java-sdk-core-1.11.844.jar:?]
at org.springframework.cloud.aws.context.support.env.AwsCloudEnvironmentCheckUtils.isRunningOnCloudEnvironment(AwsCloudEnvironmentCheckUtils.java:38) ~[spring-cloud-aws-context-2.2.2.RELEASE.jar:2.2.2.RELEASE]
......
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at com.baxter.renal.app.s3.poc.CAPDTreatmentUploadApplication.main(CAPDTreatmentUploadApplication.java:22) [classes/:?]
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.waitForConnect(Native Method) ~[?:?]
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107) ~[?:?]
答案1
得分: 3
我在本地遇到了这个问题。关闭ContextInstanceDataAutoConfiguration
是最好的解决方案。只需将以下内容添加到您的application.yml文件中:
spring.autoconfigure.exclude: org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
英文:
I had this problem locally. Turning off ContextInstanceDataAutoConfiguration
is the best solution. Just add
spring.autoconfigure.exclude: org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
to your application.yml file.
答案2
得分: 1
问题在于您的本地计算机没有实例配置文件。
如果查看堆栈跟踪,您会看到 EC2MetadataUtils.getItems()
。这正尝试从实例元数据端点 http://169.254.169.254
读取。在 EC2 实例上会迅速返回;但在您的本地计算机上,由于该 IP 地址不存在,它将超时。
如果您希望从本地计算机访问 AWS 服务,您需要使用一种在本地检索信息的凭据提供程序。我建议使用 DefaultAWSCredentialsProviderChain,它会查找本地配置(可以在 $HOME/.aws
中配置,也可以通过环境变量或系统属性配置),并且还支持实例配置文件(以防您在 EC2 实例上运行)。
英文:
The problem is that your local machine doesn't have an instance profile.
If you look at the stack trace, you'll see EC2MetadataUtils.getItems()
. This is trying to read from the instance metadata endpoint, http://169.254.169.254
. On an EC2 instance that returns quickly; on your local machine it will time-out because that IP address doesn't exist.
If you're looking to consume AWS services from your local machine, you will have to use a credentials provider that retrieves the information locally. I recommend using DefaultAWSCredentialsProviderChain, which looks for local configuration (either in $HOME/.aws
or via environment variables or system properties), and also supports instance profiles (in case you're running on an EC2 instance).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论