标签: spring-cloud-aws

在Spring Cloud AWS中禁用Cloudformation

如何在使用Spring Cloud AWS的Spring启动应用程序中禁用Cloudformation?

在亚马逊上运行我的应用程序时,我一直收到此错误:

...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method 'stackResourceRegistryFactoryBean' threw exception; nested exception is com.amazonaws.AmazonServiceException: Stack for i-b5ce9e32 does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 75b3076a-176d-11e6-90cc-b55a643dc6d6)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 82 more
Caused by: com.amazonaws.AmazonServiceException: Stack for i-b5ce9e32 does not exist (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 75b3076a-176d-11e6-90cc-b55a643dc6d6)
        at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1389)
        at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:902)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.ja
...
Run Code Online (Sandbox Code Playgroud)

我不想使用cloudformation.(至少现在(是.)

java spring amazon-web-services spring-cloud spring-cloud-aws

12
推荐指数
1
解决办法
5905
查看次数

使用 Spring Cloud AWS RDS Aurora 的 Spring Boot 应用程序 - 如何分发读取查询

我有一个使用 AWS RDS 数据库的 Spring Boot 应用程序。

我正在尝试让 RDS Aurora / Postgres DB 与只读副本一起使用。我已经运行了应用程序,但是我看不到任何流向读取器节点的流量。

设置的是 Spring boot (2.2.7)、spring cloud aws 2.2.4-RELEASE、spring data (JpaRepository)。

RDS Aurora 集群有 2 个节点、1 个读取器和 1 个写入器,如下所示: AWS RDS 配置

控制器 GET 方法注释为@Transactional(readOnly = true)

    @RequestMapping(
            value = "/counters",
            produces = {"application/json"},
            method = RequestMethod.GET
    )
    @ResponseBody
    @Transactional(readOnly = true)
    public ResponseEntity<List<Counter>> getCounters()  {
        return ResponseEntity.of(Optional.of(this.counterDAO.findAll()));
    }
Run Code Online (Sandbox Code Playgroud)

最后Spring Cloud AWS配置

cloud:
  aws:
    region:
      static: ap-southeast-2
    credentials:
      accessKey: ${ACCESS_KEY}
      secretKey: ${SECRET_KEY}
    rds:
      rds-db-cluster-instance-1:
        password: ${POSTGRES_PASSWORD}
        username: postgres
        readReplicaSupport: "true" …
Run Code Online (Sandbox Code Playgroud)

java spring-boot amazon-aurora spring-cloud-aws

12
推荐指数
1
解决办法
5759
查看次数

将 localstack 与 Spring Cloud AWS 2.3 结合使用时出现未知主机

AWS S3 的“ResourceLoader”可以很好地处理这些属性:

\n
cloud:\n  aws:\n    s3:\n        endpoint: s3.amazonaws.com     <-- custom endpoint added in spring cloud aws 2.3\n    credentials:\n        accessKey: XXXXXX\n        secretKey: XXXXXX\n    region:\n        static: us-east-1\n    stack:\n        auto: false\n
Run Code Online (Sandbox Code Playgroud)\n

但是,当我在本地启动 localstack 容器并尝试将其与这些属性一起使用时(根据此发行文档:https ://spring.io/blog/2021/03/17/spring-cloud-aws-2-3 -现在可用):

\n
cloud:\n  aws:\n    s3:\n        endpoint: http://localhost:4566\n    credentials:\n        accessKey: test\n        secretKey: test\n    region:\n        static: us-east-1\n    stack:\n        auto: false\n
Run Code Online (Sandbox Code Playgroud)\n

我得到这个例外:

\n
\n

17:12:12.130 [reactor-http-nio-2] 错误 org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler - [23efd000-1] 500 HTTP GET“/getresource/test”\ncom 服务器错误.amazonaws.SdkClientException:无法执行 HTTP 请求:mybucket.localhost\nat com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207) ~[aws-java-sdk-core-1.11.951.jar: ?]\n抑制:reactor.core.publisher.FluxOnAssembly$OnAssemblyException:\n在以下站点观察到错误:\n|_ checkpoint \xe2\x87\xa2 org.springframework.boot.actuate.metrics.web .reactive.server.MetricsWebFilter [DefaultWebFilterChain]\n|_ 检查点 \xe2\x87\xa2 …

spring-cloud-aws localstack

10
推荐指数
1
解决办法
5780
查看次数

无法检索请求的元数据 /latest/meta-data/public-hostname

我正在为 AWS Kinesis 部署带有 spring-cloud-stream 和 binder 的 springboot 应用程序。如果 beanstalk 配置了公共 ip,则该应用程序在部署在 aws elastic beanstalk 上时工作正常。当我们将 beanstalk 设置为私有 ip 时,应用程序会在部署时抛出警告,因为无法从 aws 获取一些元数据。

为什么要尝试获取这些资源?有一些解决方法可以删除此警告吗?

这些是在部署应用程序并且没有在 ec2 上设置公共 ip 时抛出的警告。

 com.amazonaws.util.EC2MetadataUtils      : Unable to retrieve the requested metadata (/latest/meta-data/public-ipv4). The requested metadata is not found at http://169.254.169.254/latest/meta-data/public-ipv4

com.amazonaws.SdkClientException: The requested metadata is not found at http://169.254.169.254/latest/meta-data/public-ipv4
        at com.amazonaws.internal.EC2CredentialsUtils.readResource(EC2CredentialsUtils.java:122)
        at com.amazonaws.internal.EC2CredentialsUtils.readResource(EC2CredentialsUtils.java:82)
        at com.amazonaws.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:400)
        at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:369)
        at com.amazonaws.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:365)
        at org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceDataPropertySource.getProperty(AmazonEc2InstanceDataPropertySource.java:89)
        at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.collectEncryptedProperties(EnvironmentDecryptApplicationInitializer.java:199)
        at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:166)
        at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.initialize(EnvironmentDecryptApplicationInitializer.java:96)
        at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:649)
        at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at …
Run Code Online (Sandbox Code Playgroud)

spring-boot amazon-elastic-beanstalk spring-cloud-stream spring-cloud-aws

9
推荐指数
1
解决办法
7825
查看次数

将SqsListener与SNS和SQS结合使用

我正在使用spring-cloud-awsSqsListener从AWS的简单队列服务(SQS)接收JSON格式的 AWS SNS HTTP通知。

这是侦听器的代码:

@SqsListener(value = "my-queue", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void handle(final MyObject obj) throws Exception {
// ...
}
Run Code Online (Sandbox Code Playgroud)

上面链接的文档仅关于向队列发送和读取普通序列化对象,我认为接收SNS消息应该可以立即使用。但是我最终收到转换错误:

10:45:51.480 [simpleMessageListenerContainer-2]错误oscamlSimpleMessageListenerContainer-处理消息时遇到异常。org.springframework.messaging.MessagingException:调用处理程序方法时发生异常;嵌套的异常是org.springframework.messaging.converter.MessageConversionException:未找到可转换为com.myproject.model.MyObject类的转换器,message = GenericMessage

我还尝试创建一个包装对象,该包装对象看起来像上面链接的预期的SNS Json格式,但是我一直收到相同的异常。唯一有效的类型是签名中的字符串。SNS是否应该自动转换?

java spring amazon-web-services spring-cloud spring-cloud-aws

8
推荐指数
1
解决办法
6383
查看次数

Spring Boot应用程序通过AWS SES发送简单电子邮件所需的配置步骤是什么?

今天我一直在和它斗争几个小时.我开始使用http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_sending_mails上的文档,这些文档并没有真正说明具体步骤.它只是说开发人员可以包含Bean XML然后自动装配MailSender.我已尝试过以及许多变种,并且无法使用spring-cloud-aws使其工作.我最终直接使用了aws-java-sdk-ses并手动配置了这个类.

这是一个简单的项目,展示了我的尝试:https: //github.com/deinspanjer/aws-ses-test

这个项目编译,但当我运行它时,我得到:

Parameter 0 of constructor in com.example.awssestest.AwsSesTestApplication required a bean of type 'org.springframework.mail.MailSender' that could not be found.
- Bean method 'mailSender' not loaded because @ConditionalOnClass did not find required class 'javax.mail.internet.MimeMessage'
- Bean method 'simpleMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
- Bean method 'javaMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
Run Code Online (Sandbox Code Playgroud)

如果我尝试添加javax-mail(https://github.com/deinspanjer/aws-ses-test/tree/try-with-javax-mail-api),则错误将更改为:

Parameter 0 of constructor in com.example.awssestest.AwsSesTestApplication required …
Run Code Online (Sandbox Code Playgroud)

amazon-ses spring-boot aws-java-sdk spring-cloud-aws

8
推荐指数
1
解决办法
4214
查看次数

使用 Spring Cloud AWS 自动配置承担角色

为了向 SNS 发布消息,我需要承担正确的角色,因此在使用 AWS SDK 时,我创建了一个 AmazonSNS bean,如下所示:

@Bean
public AmazonSNS amazonSnsClient(
        @Value("${cloud.aws.credentials.accessKey}") String accessKey,
        @Value("${cloud.aws.credentials.secretKey}") String secretKey,
        @Value("${cloud.aws.role.publisherArn}") String publisherRoleArn
) {
    AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
            .withRegion(EU_CENTRAL_1)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
            .build();
    STSAssumeRoleSessionCredentialsProvider credentialsProvider = new STSAssumeRoleSessionCredentialsProvider
            .Builder(publisherRoleArn, SESSION_NAME)
            .withStsClient(stsClient)
            .build();
    return AmazonSNSClientBuilder.standard()
            .withRegion(EU_CENTRAL_1)
            .withCredentials(credentialsProvider)
            .build();
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试对 Spring Cloud AWS Messaging & Autoconfiguration 做同样的事情,但到目前为止我没有找到有关该主题的任何信息。我的application.yml看起来像这样

cloud:   
    aws:
        credentials:
            accessKey: ***
            secretKey: ***
            instanceProfile: true
        region:
            static: eu-central-1
Run Code Online (Sandbox Code Playgroud)

它是否受 Spring 支持而我只是没能找到它,还是应该坚持使用 AWS SDK?

amazon-web-services aws-sdk spring-cloud-aws

7
推荐指数
1
解决办法
2351
查看次数

设置手动确认 SQS 消息的 Spring Cloud AWS 问题

我正在尝试使用 spring-cloud-aws-messaging 手动删除 AWS SQS 消息来实现逻辑。此功能是在测试示例中此票证 范围内实现的

@SqsListener(value = "queueName", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void listen(SqsEventDTO message, Acknowledgment acknowledgment) {

    LOGGER.info("Received message {}", message.getFoo());
    try {
        acknowledgment.acknowledge().get();
    } catch (InterruptedException e) {
        LOGGER.error("Opps", e);
    } catch (ExecutionException e) {
        LOGGER.error("Opps", e);
    }
}
Run Code Online (Sandbox Code Playgroud)

但面对意外的异常

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance oforg.springframework.cloud.aws.messaging.listener.Acknowledgement(no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

解决方案SqsMessageDeletionPolicy.ON_SUCCESS有效,但我想避免抛出异常。 …

amazon-sqs spring-cloud-aws

7
推荐指数
2
解决办法
3834
查看次数

如何为测试禁用 AWS 参数存储自动配置?

我已经spring-cloud-starter-aws-parameter-store-config按照spring 文档中的说明添加了依赖项。现在,对于单元测试,我想禁用参数存储配置。但是做不到。

我尝试在 test/application.properties 中设置以下属性

 aws.paramstore.enabled=false
Run Code Online (Sandbox Code Playgroud)

还试图排除AwsParamStoreBootstrapConfiguration.class来自AutoConfiguration但仍然没有工作。

例外

引起:org.springframework.beans.BeanInstantiationException:无法实例化[com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement]:工厂方法'ssmClient'抛出异常;嵌套异常是 com.amazonaws.SdkClientException: Unable to find a region via the region provider chain。必须在构建器或设置环境中提供显式区域以提供区域。在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] 在 org.springframework.beans.factory。 support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ... 83个常见框架省略导致:com.amazonaws.SdkClientException:无法通过区域提供商链找到区域。必须在构建器或设置环境中提供显式区域以提供区域。在 com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371) ~[aws-java-sdk-core-1.11.336.jar:na] 在 com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties( AwsClientBuilder.java:337) ~[aws-java-sdk-core-1.11.336.jar:na] 在 com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46) ~[aws-java-sdk -core-1.11.336.jar:na] 在 com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder.defaultClient(AWSSimpleSystemsManagementClientBuilder.java:44) ~[aws-java-sdk-ssm-1.11.336.jar:na] 在 org .springframework.cloud.aws.autoconfigure.paramstore.AwsParamStoreBootstrapConfiguration。

java spring unit-testing spring-boot spring-cloud-aws

7
推荐指数
1
解决办法
3376
查看次数

Spring Boot 中具有不同凭证的多个 AWS SQS 队列

我有一个 Spring Boot 应用程序,想要从多个 AWS SQS 队列接收消息。这些队列都有自己的凭据(遗憾的是我对此无能为力)。这些凭证都不能访问其他队列之一,它们都仅限于一个队列。

只需一个队列和凭据,这很简单。我只需提供 Bean 形式的凭据并用\AWSCredentialsProvider注释我的方法。 但我不知道如何使用多个凭据来做到这一点。@SqsListener@EnableSqs

注释@SqsListener无法提供凭据、预配置AmazonSqs对象或其他任何有帮助的内容。

我寻找一种通过扩展CredentialsProviderAmazonSqs客户端来将队列映射到凭据的方法,但无济于事。
我什至尝试将凭证注入 AmazonHttpClient 的标头中,但这也是不可能的。

我尝试创建手动监听 SQS 队列所需的一切。但我坚持为SimpleMessageListenerContainer.
所需的QueueMessageHandler仅在使用应用程序上下文创建为 bean 时才有效。否则它不会查找用 注释的方法@SqsListener
遗憾的是,我能找到的唯一教程或示例要么使用 JMS(我想避免使用 JMS),要么仅使用@SqsListener一个队列的注释。

还有其他方法可以为多个队列提供不同的凭据吗?

我的测试代码:

@Component
@Slf4j
public class TestOneQueueA {

  public static final String QUEUE_A = "TestOneQueueA";

  public TestOneQueueA(Cloud cloud, ResourceIdResolver resourceIdResolver) {
    SqsServiceInfo serviceInfo = (SqsServiceInfo) cloud.getServiceInfo(QUEUE_A);
    AWSStaticCredentialsProvider credentialsProvider =
        new AWSStaticCredentialsProvider(new BasicAWSCredentials(serviceInfo.getAccessKey(),
            serviceInfo.getSecretAccessKey()));

    AmazonSQSAsync …
Run Code Online (Sandbox Code Playgroud)

java spring amazon-sqs spring-boot spring-cloud-aws

7
推荐指数
1
解决办法
6297
查看次数