I am new to Dynamodb and learning currently. I am using python to query dynamodb to get some records based on a IF condition.
I have a dynamodb table cus_token, has only two attributes a) customerId and b) token
When a user provides token, check if that token exists in the cus_token table, and if it exists I want to query out and fetch the customerID for that token. I tried to to do it this way
Suppose
user_input = "Rooxp9" (this is a token in the cus_token table)
first get all the values with token attribute
import boto3
import json
def gettokens(y):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('cus_token')
response = table.scan()
tokens = []
for i in response['Items']:
nameList.append(i['token'])
return tokens
temp = gettokens(cus_token)
Check using IF condition
for item in temp:
if item == user_input:
"Here I want to write the code to fetch the customerID"
