Michael
Michael

Reputation: 2387

Get an AWS Table Resource using the low-level Client

My goal is to get similar object that I get through:

dynamodb = boto3.resource(service_name='dynamodb')        
self._table = dynamodb.Table(name)

but through the Client object. How can I reference a DynamoDB table through the low-level Client object?

Here is my code,

import boto3

cli = boto3.client('dynamodb')
cli.get_item(TableName=TABLE_NAME)

but I get the following error:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Missing required parameter in input: "Key"

from the official documentation I saw that the Key is a dictionary of returned properties, but couldn't wrap my head around what it actually represents.

I'd really appreciate any help.

Thanks in advance.

Upvotes: 1

Views: 262

Answers (1)

Vova
Vova

Reputation: 3537

You should use The primary key attribute values that define the items and the attributes associated with the items.

boto_client.get_item(TableName='string', Key={})

by client.get_item:

client = boto3.client('dynamodb')
client.get_item(TableName='YourTable', Key={'PrimaryKeyName': {'ValueType':'Value'}})

where:

  • YourTable - table name
  • KeyName - primary key
  • ValueType - S, N, B, SS, NS, BS, M
  • Value - your value of item you want to get from table

notice, that if your value is Number you use N but value will be inside quotes anyway

Upvotes: 3

Related Questions