0
votes

I'm using Lambda, API-gateway & Dynamodb using python 3.6 I have a dynamodb table for order id:

  • orderId (primary Key|String)
  • orderStatus (String)
  • orderCode (String)
  • date (String)

OrderId is unique. Whenever I try to query by date I get the following error:

{
  "errorMessage": "An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema",
  "errorType": "ClientError",
  "stackTrace": [
    [
      "/var/task/lambda_function.py",
      8,
      "lambda_handler",
      "\"date\":day"
    ]

My code:

    import boto3
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('Shops')

    def lambda_handler(event, context):
        day = event['day']
        resp = table.get_item(Key={
        "date":day
        })
        return resp['Item']

I want to write a query that takes one date as input and will return all orders on that day:

This was my input:

{
  "day": "191215"
}
1

1 Answers

1
votes

What you are trying to do is not possible in DynamoDB. You always have to provide a primary key, whether you query or trying to get a specific item.

Of course, you can scan the table but as you are probably aware this is a very expensive operation.

You can always create a Global Secondary Index with date as it's primary key and query the index instead.