如何在本地使用 spring-cloud-starter-aws 运行应用程序? [英] How to run the app with spring-cloud-starter-aws locally?

查看:41
本文介绍了如何在本地使用 spring-cloud-starter-aws 运行应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在本地运行基于 Spring Boot 的应用程序.它使用 spring-cloud-starter-aws 依赖项.
问题是它总是尝试连接到 EC2 元数据服务.设置cloud.aws.*"属性没有帮助.
我希望将使用默认的 AWS 凭证链,将从 AWS 首选方式之一(例如 ~/.aws/config 和 ~/.aws/credentials 文件)读取凭证和区域.
我试图设置 cloud.aws.credentials.useDefaultAwsCredentialsChain 属性,但 spring-cloud-starter-aws 不在乎

I need to run Spring Boot based app locally. It uses spring-cloud-starter-aws dependency.
The problem is that it tries to connect to EC2 metadata service always. Setting "cloud.aws.*" properties doesn't help.
I expect that default AWS credentials chain will be used, credentials and region will be read from one of AWS preferred way (e.g. ~/.aws/config and ~/.aws/credentials files).
I tried to set cloud.aws.credentials.useDefaultAwsCredentialsChain property but spring-cloud-starter-aws doesn't care

我发现 examples 出于非常奇怪的原因运行使用 CloudFormation 堆栈本地应用.

I found examples that use CloudFormation stack for very strange reason to run the app locally.

当我使用 AWS SDK for Java 时,默认使用 AWS 链没有任何问题 - 我不需要为应用程序的本地运行做任何特定的事情(在本地它从文件中读取凭证,在 EC2 上它使用实例元数据服务).但是对于 Spring Boot,它不能开箱即用,我需要以某种方式启用本地运行.

When I use AWS SDK for Java default AWS chain is used without any issues - I don't need to do anything specific for local running of the application (locally it reads credentials from files and on EC2 it uses instance metadata service). But with Spring Boot it doesn't work out of the box and I need to enable local running somehow.

我使用的是 2.2.2.RELEASE 版本的 Spring Boot 和 2.2.1.RELEASE 版本的 Spring Cloud.我感觉他们引入了回归,因为在以前的版本中它没有问题.

I use 2.2.2.RELEASE version of Spring Boot and 2.2.1.RELEASE version of Spring Cloud. I have a feeling they introduced regression, because in previous versions it worked without problems.

知道如何在本地运行应用程序吗?

Any ideas how to run the app locally?

推荐答案

在配置中添加以下几行有助于:

Adding the following lines to configuration helps:

cloud.aws.region.static=my region
cloud.aws.stack.auto=false
spring.autoconfigure.exclude=org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration

因此 Spring 使用 AWS 默认链但仅用于凭证.AWS 开发工具包也将其用于区域和其他配置参数.所以这肯定是 Spring 错误.
在应用程序启动期间,它仍然会发出有关没有连接到实例元数据服务的警告,但或多或​​少该解决方案可用于本地运行.

So Spring uses AWS default chain but only for credentials. AWS SDK uses it for region and other configuration parameters too. So this is Spring bug for sure.
It still gives a warning about no connection to instance metadata service once during application start but more or less this solution can be used for local running.

如果我们没有排除 CloudWatchExportAutoConfiguration 的最后一行,那么在关闭应用程序时堆栈跟踪中会有很多异常.我在我的应用中使用 CloudWatch 指标.

If we don't have the last line with excluding CloudWatchExportAutoConfiguration, there will be many exceptions in stack trace while closing the app. I use CloudWatch metrics in my app.

我想排除 aws 自动配置的原因是它与启动执行器有冲突,但我不确定.

I guess rationale behind excluding aws auto configuration is that it has conflicts with boot actuator but I'm not sure.

这篇关于如何在本地使用 spring-cloud-starter-aws 运行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆