[英]“DynamoDbException: An unknown operation was requested.” problem when using LocalStack docker container, Java testcontainers
I have application what uses DynamoDB.我有使用 DynamoDB 的应用程序。 I raise Dynamo with docker and work with it using DynamoDbClient.
我使用 docker 提升 Dynamo 并使用 DynamoDbClient 使用它。 Actually, I have been using docker for dynamo for some time.
实际上,我一直在使用 docker 作为 dynamo。 I used testcontainers lib and created GenericContainer with "amazon/dynamodb-local:latest" image.
我使用了 testcontainers lib 并使用“amazon/dynamodb-local:latest”图像创建了 GenericContainer。 And all was fine.
一切都很好。 But recently I started using other AWS technologies such as S3 and SQS, so I decided to use LocalStack Container for all this technologies.
但最近我开始使用其他 AWS 技术,例如 S3 和 SQS,因此我决定将 LocalStack Container 用于所有这些技术。 Use the same clients and configuration.
使用相同的客户端和配置。 And all is good with S3 and SQS, but Dynamo started failing on executeStatement method which process my PartiQL statments(it is important to me to use exactly PartiQL, not embedded methods in sdk for Java) with exception "DynamoDbException: An unknown operation was requested".
S3 和 SQS 一切都很好,但是 Dynamo 开始在处理我的 PartiQL statments 的 executeStatement 方法上失败(对我来说完全使用 PartiQL,而不是 Java sdk 中的嵌入式方法很重要),出现异常“DynamoDbException:请求了未知操作”。 I cant understand where is the problem because I changed only docker container.
我不明白问题出在哪里,因为我只更改了 docker 容器。 Here is me code for docker raising:
这是我的码头工人代码:
private static final DockerImageName DOCKER_IMAGE_NAME = DockerImageName.parse("localstack/localstack")
.withTag("latest");
GenericContainer<?> localStackContainer = new LocalStackContainer(DOCKER_IMAGE_NAME)
.withServices(SQS, S3, DYNAMODB)
localStackContainer.start();
Configuration: (It is written on scala, but it's not important for this question) *Port in endpoint dynamically replaced with a docker-created port配置:(它是写在scala上的,但对于这个问题并不重要)*端点中的端口动态替换为docker创建的端口
dynamodb {
region = "eu-central-1"
endpoint = "http://localhost:4569"
accessKeyId = "DEFAULT_ACCESS_KEY"
secretAccessKey = "DEFAULT_SECRET"
sessionToken = "DEFAULT_SESSION_TOKEN"
}
Client creating:客户端创建:
@Bean
public DynamoDbClient dynamodb(final GlobalConfiguration globalConfiguration) {
GlobalConfiguration.Dynamodb ddb = globalConfiguration.dynamodb();
URI uri = URI.create(ddb.endpoint());
Region region = Region.of(ddb.region());
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(ddb.accessKeyId(), ddb.secretAccessKey());
StaticCredentialsProvider staticCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials);
return DynamoDbClient.builder()
.endpointOverride(uri)
.region(region)
.credentialsProvider(staticCredentialsProvider)
.build();
}
Place where code fails:代码失败的地方:
dynamoDbClient.executeStatement(builder -> builder.statement(query));
Looks like localstack's DynamoDB implementation doesn't support PartiQL just yet .看起来 localstack 的 DynamoDB 实现还不支持 PartiQL 。 Hopefully soon!
希望不久!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.