using boto3 I am trying to get a object in a dynamodb table.
following this stack overflow post the correct syntax is
client = boto3.client('dynamodb')
response = client.get_item(TableName='Garbage_collector_table', Key={'topic':{'S':str(my_topic)}})
Not able to get_item from AWS dynamodb using python?
http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html
I have tried various iterations to get proper syntax my current is this
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')
payload = {
"HCPCSCodeSet": event['hcpcs_codes']
}
response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
Key={'HCPCSCodeSet':{'S': payload}})
print('here comes the tacos brah')
print(response)
Im not sure what this thing wants. What is the proper syntax?
Invalid type for parameter Key.HCPCSCodeSet, value: tacoman, type: <class 'str'>, valid types: <class 'dict'>
Traceback (most recent call last):
File "/var/task/lambdafile.py", line 18, in lambda_handler
Key= payload)
File "/var/task/botocore/client.py", line 415, in _api_call
the primary key name for the dynamodb database is
Partition key
HCPCSCodeSet (String)
CodePudding user response:
This code:
payload = {
"HCPCSCodeSet": event['hcpcs_codes']
}
response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
Key={'HCPCSCodeSet':{'S': payload}})
Ends up trying to send the following to DynamoDB:
Key={'HCPCSCodeSet':{'S': {
"HCPCSCodeSet": event['hcpcs_codes']
}}}
Which is obviously not correct. It's unclear why you are building the payload
object at all. You could just do this:
response = client.get_item(TableName="mce-hcpcs-associations-table-dev",
Key={'HCPCSCodeSet':{'S': event['hcpcs_codes']}})