英文:
Why am I getting 504 Gateway Time-out after updating aws-java-sdk version in Spring-Boot app on AWS?
问题
我有一个Spring Boot应用程序,它部署在AWS EKS集群上。有一个Maven依赖项 'aws-java-sdk' 。早些时候,它在旧版本1.11.52下正常运行,但当我将版本更新为1.12.470时,它开始出现504网关超时错误。
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.12.470</version>
</dependency>
还检查了与HTTP错误相关的CloudWatch,没有错误出现。
英文:
I am having a spring boot app and it's deployed over the AWS EKS cluster. There is one maven dependency 'aws-java-sdk' . Earlier it was running fine with the older version - 1.11.52, but when I have updated the version to - 1.12.470. It start giving me 504 Gateway Time-out error.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.12.470</version>
</dependency>
Also check with cloudwatch related to HTTP Errors, no errors are coming.
答案1
得分: 1
你正在使用AWS SDK for Java V1,这不是最佳实践。强烈建议您考虑迁移到AWS SDK for Java V2。POM依赖如下:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.45</version>
<type>pom</type>
<scope>import</scope>
</dependency>
这是开发指南:
AWS SDK for Java 2.x是版本1.x代码基础的重大重写。它构建在Java 8+之上,并添加了一些经常被请求的功能。这些功能包括对非阻塞I/O的支持以及在运行时插入不同的HTTP实现的能力。
AWS SDK for Java V2与Spring Boot非常兼容。请参考此示例:
英文:
You are using AWS SDK for Java V1 - which is not best practice. You should strongly consider moving to AWS SDK for Java V2. The POM dependency is:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.45</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Here is the DEV Guide:
Developer Guide - AWS SDK for Java 2.x
The AWS SDK for Java 2.x is a major rewrite of the version 1.x code base. It’s built on top of Java 8+ and adds several frequently requested features. These include support for non-blocking I/O and the ability to plug in a different HTTP implementation at runtime.
The AWS SDK for Java V2 works great with Spring Boot. Refer to this example:
答案2
得分: 0
通常是与安全性/防火墙相关的问题...
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-504-gateway-timeout.html
HTTP 504状态码(网关超时)表示当CloudFront将请求转发到源服务器(因为请求的对象不在边缘缓存中)时,以下情况之一发生:
源服务器向CloudFront返回了HTTP 504状态码。
源服务器在请求过期之前未响应。
如果流量被防火墙或安全组阻止,或者源服务器无法通过互联网访问,CloudFront将返回HTTP 504状态码。首先检查这些问题。然后,如果访问不是问题的原因,请探查应用程序延迟和服务器超时,以帮助您识别并修复问题。
英文:
Usually security/firewall related issue somewhere...
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-504-gateway-timeout.html
> An HTTP 504 status code (Gateway Timeout) indicates that when
> CloudFront forwarded a request to the origin (because the requested
> object wasn't in the edge cache), one of the following happened:
>
> The origin returned an HTTP 504 status code to CloudFront.
>
> The origin didn't respond before the request expired.
>
> CloudFront will return an HTTP 504 status code if traffic is blocked
> to the origin by a firewall or security group, or if the origin isn't
> accessible on the internet. Check for those issues first. Then, if
> access isn't the problem, explore application delays and server
> timeouts to help you identify and fix the issues.
答案3
得分: 0
我通过只添加我需要的依赖项来解决了这个问题-
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.12.472</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-rds</artifactId>
<version>1.12.472</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cognitoidp</artifactId>
<version>1.12.472</version>
</dependency>
aws-sdk-java的问题在于它下载了完整的jar包,这些jar包是aws sdk生态系统的一部分,而其他的jar包可能会与EKS发生冲突,引发问题。还有一点需要注意的是,所有的aws-sdk jar包版本都应该完全相同,因为它们在内部也依赖于其他aws jar包,这也可能会导致问题。
建议只使用你需要的相关jar包,而不是整个包。
英文:
I was able to solve it by adding only the dependency I need-
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.12.472</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-rds</artifactId>
<version>1.12.472</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cognitoidp</artifactId>
<version>1.12.472</version>
</dependency>
The problem with aws-sdk-java is that it download the complete jars package which are the part of aws sdk ecosystem and the others jars may conflict with the EKS causing the issues. One more thing that all the aws-sdk jars version should be exact same, since internally they have dependency on other aws jars as well which also might create problems.
It was advisable to use the relevant jars that you needed, not the complete package.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论