in design-patterns/query_city_dept.py [0:0]
def query_gsi(tableName, value1, value2):
dynamodb = boto3.resource(**boto_args)
table = dynamodb.Table(tableName)
if value2 == "-":
ke = Key('GSI_3_PK').eq("state#{}".format(value1))
else:
ke = Key('GSI_3_PK').eq("state#{}".format(value1)) & Key('GSI_3_SK').begins_with(value2)
response = table.query(
IndexName='GSI_3',
KeyConditionExpression=ke
)
print('List of employees . State: %s' % (value1))
for i in response['Items']:
city,dept = i['city_dept'].split('#')
print('\tName: %s. City: %s. Dept: %s' % (i['name'], city, dept))
return response['Count']