Here is the scheme of my dynamoDB table
Here is the way I am requesting my get_item
if event['hcpcs_codes'] != None:
# codes must be in numerical, alphabetical order
# multi codes should be seperated by a comma with no spaces
client = boto3.client('dynamodb')
response = None
try:
response = client.get_item(TableName=os.environ['TABLE'],
Key={'antecedents':{'S': str(event['hcpcs_codes'])}})
except ValidationError as e:
print(e)
print('here comes the tacos brah')
print(response)
but I get the error:
[ERROR] ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
Traceback (most recent call last):
File "/var/task/lambdafile.py", line 19, in lambda_handler
Key={'antecedents':{'S': str(event['hcpcs_codes'])}})
File "/var/task/botocore/client.py", line 415, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/task/botocore/client.py", line 745, in _make_api_call
raise error_class(parsed_response, operation_name)
and according to the docs. It looks like Im doing this right
response = client.get_item(
TableName='string',
Key={
'string': {
'S': 'string',
'N': 'string',
'B': b'bytes',
'SS': [
'string',
],
'NS': [
'string',
],
'BS': [
b'bytes',
],
'M': {
'string': {'... recursive ...'}
},
'L': [
{'... recursive ...'},
],
'NULL': True|False,
'BOOL': True|False
}
},
AttributesToGet=[
'string',
],
ConsistentRead=True|False,
ReturnConsumedCapacity='INDEXES'|'TOTAL'|'NONE',
ProjectionExpression='string',
ExpressionAttributeNames={
'string': 'string'
}
)
CodePudding user response:
You must supply both the partition key and the sort key when using GetItem if the table has a sort key set.