简体   繁体   中英

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. The Java program is an AWS sample.

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.

I have set the following values in in ~/.aws/config and ~/.aws/credentials through running aws configure in the AWS CLI.

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

I have the Local DYnamoDB JAR running with this.

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

Howevwer, I'm getting this Exception.

AmazonDynamoDBException: The security token included in the request is invalid.

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. It looks like it is pointing to DynamoDB proper.

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.

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.

The solution would be to explicitly connect to the local DynamoBD (needed to be installed) This is the code to achieve it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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