简体   繁体   English

如何配置 AWS DynamoDB Camel 组件

[英]How to configure AWS DynamoDB Camel component

I am trying to POC accessing DynamoDB via an Apache Camel application.我正在尝试 POC 通过 Apache Camel 应用程序访问 DynamoDB。 Obviously Dynamo DB will run in AWS but for development purposes we have it running locally as a docker container.显然 Dynamo DB 将在 AWS 中运行,但出于开发目的,我们将其作为 docker 容器在本地运行。

It was very easy to create a Dynamo BD table locally and put some items in there manually.在本地创建 Dynamo BD 表并手动将一些项目放入其中非常容易。 I used for this my intelij Dynamo DB console and all I had to provide was a custom end point http://localhost:8000 and the Default credential provider chain.我为此使用了我的 intelij Dynamo DB 控制台,我所需要提供的只是一个自定义端点http://localhost:8000和默认凭证提供程序链。

Now at some certain times of the day I would like to trigger a job that will scan the Dynamo DB items and perform some actions on the returned data.现在,在一天中的某些特定时间,我想触发一个作业,该作业将扫描 Dynamo DB 项目并对返回的数据执行一些操作。

from("cron:myCron?schedule=0 */5 * * * *")
        .log("Running myCron scheduler")
        .setHeader(Ddb2Constants.OPERATION, () -> Ddb2Operations.Scan)
        .to("aws2-ddb:myTable")
        .log("Performing some work on items");

When I am trying to run my application it fails to start complaining that the security token is expired which makes me think it is trying to go to AWS rather than accessing the local.当我尝试运行我的应用程序时,它无法开始抱怨安全令牌已过期,这让我认为它正在尝试 go 到 AWS 而不是访问本地。 I was unable to find anything about how would I set this.我找不到任何关于如何设置它的信息。 The camel dynamo db component ( https://camel.apache.org/components/3.15.x/aws2-ddb-component.html ) is talking about being able to configure the component with a DynamoDbClient but this is an interface and its implementation called DefaultDynamoDbClient is not public and so is the DefaultDynamoDbClientBuilder .骆驼发电机 db 组件 ( https://camel.apache.org/components/3.15.x/aws2-ddb-component.html ) 正在谈论能够使用DynamoDbClient配置组件,但这是一个接口及其实现称为DefaultDynamoDbClient不是公开的, DefaultDynamoDbClientBuilder也是。

Assuming that you use Spring Boot as Camel runtime, the simplest way in your case is to configure the DynamoDbClient used by Camel thanks to options set in the application.properties as next:假设您使用 Spring Boot 作为 Camel 运行时,在您的情况下,最简单的方法是配置 Camel 使用的DynamoDbClient ,这要归功于application.properties中设置的选项,如下所示:

# The value of the access key used by the component aws2-ddb
camel.component.aws2-ddb.accessKey=test
# The value of the secret key used by the component aws2-ddb
camel.component.aws2-ddb.secretKey=test
# The value of the region used by the component aws2-ddb 
camel.component.aws2-ddb.region=us-east-1
# Indicates that the component aws2-ddb should use the new URI endpoint
camel.component.aws2-ddb.override-endpoint=true
# The value of the URI endpoint used by the component aws2-ddb 
camel.component.aws2-ddb.uri-endpoint-override=http://localhost:8000

For more details please refer to the documentation of those options:有关详细信息,请参阅这些选项的文档:


For other runtimes, it can be configured programatically as next:对于其他运行时,可以通过编程方式配置如下:

Ddb2Component ddb2Component = new Ddb2Component(context);
String accessKey = "test";
String secretKey = "test";
String region = "us-east-1";
String endpoint = "http://localhost:8000";
ddb2Component.getConfiguration().setAmazonDDBClient(
    DynamoDbClient.builder()
        .endpointOverride(URI.create(endpoint))
        .credentialsProvider(
            StaticCredentialsProvider.create(
                AwsBasicCredentials.create(accessKey, secretKey)
            )
        )
        .region(Region.of(region))
        .build()
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM