AmazonDynamoDBException: Consistent reads are not supported on global secondary indexes

If you try to execute a DynamoDB query against a Global Secondary Index, by default you’ll get this error:

AmazonDynamoDBException: Consistent reads are not supported on global secondary indexes (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException

To avoid this, per answers on this question, you need to call:

.withConsistentRead(false);

on your query expression.

Although the docs here suggest queries are eventually consistent by default, apparently with the DynamoDB mapping api you still need to explicitly set the consisten read = false parameter.

Serverless framework deploy for Java AWS Lambdas

The Serverless framework ‘serverless deploy’ deploys whatever .jar you have packaged and ready to go within your source project.

If you make local code changes but don’t re-build your .jar, serverless thinks you don’t have any changes to deploy:

$ serverless deploy
...
Serverless: Packaging service...
Serverless: Service files not changed. Skipping deployment...

If you’re building a maven-based project, ‘mvn clean package’ first, then run your ‘serverless deploy’.

Working with multiple AWS accounts

Using multiple AWS accounts under an Organization umbrella can be useful even at a personal level, for learning AWS features and self-training, it helps keep various projects partitioned. However, working with multiple accounts at a time can get complex, and on more than one occasion I’ve lost track of which account I’m actually working with.

If you’re working with api keypairs and don’t know which account the keypair is for, the following aws cli command is useful:

aws sts get-caller-identity

It shows you the following info:

{
  "UserId" : ... key id ...,
  "Account" : ... account id ...,
  "Arn" : ... the IAM ARN for the current userid