I’m trying to get an item from Dynamo DB table and end up getting an error message. Tried using boto3 resource and client and had no luck. Any help would be greatly appreciated.

In the table accountId is PK and comState is SK.

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('table_abc')

response = table.get_item(Key={'accountId': 'ACC123',
items = response.get('Item', None)

I’m getting the below error message.

  botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the 
  GetItem operation: The provided key element does not match the schema

  Captured logging:
  INFO:botocore.tokens:Loading cached SSO token for default

I think you need to edit the format for Key dictionary to include the value type of the key along with its value in the following format

  '<key 1>': {
    '<value type 1>': <value 1>
  '<key 2>': {
    '<value type 2>': <value 2>

Based on your code, I think the correct value type for both keys is string (S) (you can learn more about other value types here)

response = table.get_item(Key={
  'accountId': {'S': 'ACC123'},
  'comState':{'S': 'STARTED'}

If that doesn’t work, I think you also need to check if both attributes are primary keys (partition key and the sort key) in your table schema