简体   繁体   English

AWS Local DynamoDB 请求中包含的安全令牌无效

[英]AWS Local DynamoDB The security token included in the request is invalid

I am new to AWS and I am trying to perform CRUD operation on Local DynamoDB from a Java program.我是 AWS 新手,我正在尝试从 Java 程序对本地 DynamoDB 执行 CRUD 操作。 The Java program is an AWS sample. Java 程序是 AWS 示例。

I have AWS CLI installed and have set the following configuration - As per AWS documentation, I don't need a real AWS access and secret key for Local DynamoDB.我安装了 AWS CLI 并设置了以下配置 - 根据 AWS 文档,我不需要本地 DynamoDB 的真正 AWS 访问和密钥。

I have set the following values in in ~/.aws/config and ~/.aws/credentials through running aws configure in the AWS CLI.我通过在 AWS CLI 中运行 aws configure 在 ~/.aws/config 和 ~/.aws/credentials 中设置了以下值。

[default]
aws_access_key_id = ''
aws_secret_access_key = ''
[default]
region = ap-south-1

I have the Local DYnamoDB JAR running with this.我有本地 DYnamoDB JAR 运行这个。

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

And the code I'm trying to run is this.我试图运行的代码就是这个。

https://github.com/aws-samples/aws-dynamodb-examples/blob/master/src/main/java/com/amazonaws/codesamples/datamodeling/ObjectPersistenceCRUDExample.java https://github.com/aws-samples/aws-dynamodb-examples/blob/master/src/main/java/com/amazonaws/codesamples/datamodeling/ObjectPersistenceCRUDExample.java

Howevwer, I'm getting this Exception.但是,我得到了这个例外。

AmazonDynamoDBException: The security token included in the request is invalid. AmazonDynamoDBException:请求中包含的安全令牌无效。

The complete stack is this.完整的堆栈是这样的。

    Exception in thread "main" com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The security token included in the request is invalid. (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: UnrecognizedClientException; Request ID: UPGRD2BRNUN6S1702EN6N6S8RJVV4KQNSO5AEMVJF66Q9ASUAAJG)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1695)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1350)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1101)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:758)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:732)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:714)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:674)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:656)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:520)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:4192)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:4159)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeUpdateItem(AmazonDynamoDBClient.java:3868)
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:3835)
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:854)
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:594)
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:733)
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:623)
    at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.save(AbstractDynamoDBMapper.java:123)
    at com.stackroute.Main.testCRUDOperations(Main.java:60
    at com.stackroute.Main.main(Main.java:17)

Any help will be highly appreciated.任何帮助将不胜感激。 Thanks in Advance.提前致谢。

Nothing in the cited code points to the DynamoDB local instance from what I can tell.据我所知,引用的代码中没有任何内容指向 DynamoDB 本地实例。 It looks like it is pointing to DynamoDB proper.看起来它指向正确的 DynamoDB。

You need to change the endpoint to be the local version.您需要将端点更改为本地版本。 Take a look at this page .看看这个页面 It has an example of changing the endpoint to localhost:8080.它有一个将端点更改为 localhost:8080 的示例。

Precisely, the problem indeed seems to be pointing to the DynamoDB on AWS rather than a local one, although I can't validate this for the original comment because the links are broken now, at least this is what happened to me.确切地说,问题似乎确实指向 AWS 上的 DynamoDB,而不是本地的,尽管我无法验证原始评论的这一点,因为链接现在已损坏,至少这是发生在我身上的事情。

The solution would be to explicitly connect to the local DynamoBD (needed to be installed) This is the code to achieve it:解决方案是显式连接到本地 DynamoBD(需要安装)这是实现它的代码:

AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(
            // we can use any region here
            new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2"))
            .build();

This is the link to the example class mentioned on previous comments that was deleted(you will need to click on Load Diff for the DynamoDBLocalFixture.java class): https://github.com/aws-samples/aws-dynamodb-examples/commit/461b0e85bfad58f4a62c63f38426c650896fb870#diff-b331539c5e8b0398d9bbb85c5b87a4cdfa32efbefb27f68f3402c223b243b178 This is the link to the example class mentioned on previous comments that was deleted(you will need to click on Load Diff for the DynamoDBLocalFixture.java class): https://github.com/aws-samples/aws-dynamodb-examples/提交/461b0e85bfad58f4a62c63f38426c650896fb870#diff-b331539c5e8b0398d9bbb85c5b87a4cdfa32efbefb27f68f3402c223b243b178

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

相关问题 AWS Lambda + DynamoDB 请求中的安全令牌无效 - AWS Lambda + DynamoDB Invalid security token in request SQS ExpiredToken:请求中包含的安全令牌是过期状态代码:403 - SQS ExpiredToken: The security token included in the request is expired status code: 403 请求中不包含授权不记名令牌 - Authorization Bearer token is not included for request 如何在AWS中获取dynamodb的主机名而不是本地? - How to get hostname for dynamodb in AWS and NOT local? 该请求不包含在自定义过滤器中。 Spring 安全 - The request is not included in the custom filter. Spring Security 在 Spring 安全性中会话超时时,处理请求中发现的无效 CSRF 令牌的最佳方法是什么 - What is the best way to handle Invalid CSRF token found in the request when session times out in Spring security 从 AWS Credentials Provider 获取安全令牌 - Get security token from AWS Credentials Provider Spring Security Oauth2 客户端获取访问令牌失败,请求代码无效=415,消息=不支持的媒体类型 - Spring Security Oauth2 Client get access token fails with invalid request code=415, message=Unsupported Media Type 使用Java访问dynamoDB(本地)时无法加载AWS凭证错误 - Unable to load AWS credentials Error when accessing dynamoDB (local) with java Spring 安全性 - 使用请求主机名进行令牌身份验证 - Spring Security - Token authentication with request host name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM