【问题标题】:Different credentials for Kinesis Stream, DynamoDB and CloudWatch inside Spring Cloud StreamSpring Cloud Stream 中 Kinesis Stream、DynamoDB 和 CloudWatch 的不同凭证
【发布时间】:2021-03-11 15:17:32
【问题描述】:

我正在使用 Spring Cloud Stream Kinesis binder(2.1.0 版)

出于安全原因,我必须拥有一组 Kinesis 凭据和另一组 DynamoDB 和 CloudWatch 凭据。

如果 spring.cloud.stream.kinesis.binder.kplKclEnabled 设置为 false,一切正常。但如果它设置为 true 我有例外

com.amazonaws.services.kinesis.model.ResourceNotFoundException: Stream {my_stream} under account {my_account} not found

整个堆栈跟踪可在 https://pastebin.com/bjvKSzrg 获得

我想启用 KCL,请问有人知道如何避免此错误吗?

我知道发生错误是因为 cloudwatch 和 dynamodb 的用户凭据没有“看到”提到的 Kinesis 流。但是为什么他们需要看到它呢?此外,如果禁用 KCL,它会按预期工作。所以不明白为什么它不能与启用的 KCL 一起工作

这是我的属性文件

spring.main.allow-bean-definition-overriding=true
spring.cloud.stream.bindings.input.destination=streamName
spring.cloud.stream.bindings.input.group=worker
spring.cloud.stream.bindings.input.content-type=application/json
spring.cloud.stream.kinesis.bindings.input.consumer.listener-mode=batch
spring.cloud.stream.bindings.input.binder=kinesisConsumer



spring.cloud.stream.binders.kinesisConsumer.type=kinesis
spring.cloud.stream.binders.kinesisConsumer.defaultCandidate=false
spring.cloud.stream.binders.kinesisConsumer.environment.spring.main.sources=com.philips.ka.oneka.kinesis.config.KinesisOutputConfiguration

cloud.aws.stack.auto=false
cloud.aws.credentials.useDefaultAwsCredentialsChain=false
cloud.aws.credentials.instanceProfile=true

spring.cloud.stream.kinesis.binder.kplKclEnabled=true

提到的配置类

@Configuration
@EnableConfigurationProperties(AwsProperties.class)
public class KinesisOutputConfiguration {
    AwsProperties.Properties properties;

    public KinesisOutputConfiguration(AwsProperties awsProperties) {
        this.properties = awsProperties.getStreamType().get(AwsProperties.StreamType.SPECTRE);
    }

    @Bean(destroyMethod = "shutdown")
    public AmazonKinesisAsync amazonKinesis() {
        RefreshingCredentials refreshingCredentials = new RefreshingCredentials(this.properties.getRefreshed.getUrl(), this.properties.getHsdp().getClientId(),
                this.properties.getRefreshed().getClientSecret(), this.properties.getRefreshed().getUsername(), this.properties.getRefreshed().getPassword(),
                this.properties.getRefreshed().getDiscoveryUrl(), new UriTemplate("{databroker_url}/Stream/$getaccessdetails"),
                new RestTemplate());
        return AmazonKinesisAsyncClientBuilder.standard().withCredentials(credentialsProvider).withRegion("eu-west-1").build();
    }


    @Bean(destroyMethod = "shutdown")
    public AmazonCloudWatchAsync cloudWatch() {
        AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(this.properties.getAccessKey(),
                this.properties.getSecretKey()));
        return AmazonCloudWatchAsyncClientBuilder.standard().withCredentials(credentialsProvider).withRegion("us-east-2").build();
    }

    @Bean(destroyMethod = "shutdown")
    @Primary
    public AmazonDynamoDBAsync dynamoDBAsync() {
        AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(this.properties.getAccessKey(),
                this.properties.getSecretKey()));
        return AmazonDynamoDBAsyncClientBuilder.standard().withCredentials(credentialsProvider).withRegion("us-east-2").build();
    }

}

【问题讨论】:

    标签: spring-cloud-stream amazon-kinesis amazon-kcl


    【解决方案1】:

    您的配置是正确的:如果您需要为这些服务使用不同的凭据,您肯定需要为它们声明自定义 bean。 DynamoDB 和 CloudWatch 是 Kinesis Client Library 所需的服务。它一方面用于管理流分片的偏移量,另一方面用于处理集群中的消费者实例更改以实现分片独占访问。因此,事实上 Kinesis 资源必须可供 DynamoDB 和 CloudWatch 用户使用。

    在 Kinesis Client Library 中查看更多信息或询问 AWS 支持:Kinesis Binder 无法为您解决此问题...

    https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-kcl.html

    【讨论】:

    • 感谢您的快速响应和澄清!
    • 嗨@Artem Bilan,这个KCL 功能分支说不同的东西github.com/awslabs/amazon-kinesis-client/pull/111 你知道它可以在Spring Cloud Stream 中使用吗?
    • 如果还创建了 KinesisClientLibConfiguration 是可以实现的。一件奇怪的事情是,需要为 KinesisClientLibConfiguration 和(Kinesis、CloudWatch、DynamoDB)bean 定义凭据。因为 1. Kcl 实际使用 KinesisClientLibConfiguration 中定义的凭据 2. kinesis、cloudwatch、dynamodb 的默认构建器在没有显式设置凭据的情况下将无法工作。
    • 没错。因为默认 bean 依赖于自动配置的 AWS 凭证 - “配置约定”。其他一切都取决于 AWS KCL。或者您是否看到在 binder 项目中可以改进的地方?例如,为 KCL 摆脱那些 bean,但让依赖 KinesisClientLibConfiguration
    • 是的,我想选择只创建 KinesisClientLibConfiguration。目前这不起作用,我需要创建所有 bean(Kinesis、Cloudwatch、Dynamodb、KinesisClientLibConfiguration)。不确定是 binder 还是 kcl 问题。
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 2019-10-03
    • 2018-05-18
    • 2016-11-29
    • 2019-12-22
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    相关资源
    最近更新 更多