簡體   English   中英

如何配置 AWS DynamoDB Camel 組件

[英]How to configure AWS DynamoDB Camel component

我正在嘗試 POC 通過 Apache Camel 應用程序訪問 DynamoDB。 顯然 Dynamo DB 將在 AWS 中運行,但出於開發目的,我們將其作為 docker 容器在本地運行。

在本地創建 Dynamo BD 表並手動將一些項目放入其中非常容易。 我為此使用了我的 intelij Dynamo DB 控制台,我所需要提供的只是一個自定義端點http://localhost:8000和默認憑證提供程序鏈。

現在,在一天中的某些特定時間,我想觸發一個作業,該作業將掃描 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");

當我嘗試運行我的應用程序時,它無法開始抱怨安全令牌已過期,這讓我認為它正在嘗試 go 到 AWS 而不是訪問本地。 我找不到任何關於如何設置它的信息。 駱駝發電機 db 組件 ( https://camel.apache.org/components/3.15.x/aws2-ddb-component.html ) 正在談論能夠使用DynamoDbClient配置組件,但這是一個接口及其實現稱為DefaultDynamoDbClient不是公開的, DefaultDynamoDbClientBuilder也是。

假設您使用 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

有關詳細信息,請參閱這些選項的文檔:


對於其他運行時,可以通過編程方式配置如下:

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