Skip to content
Advertisement

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement