def query_responsecode_shard()

in design-patterns/query_responsecode.py [0:0]


def query_responsecode_shard(tableName, shardid, responsecode, date="all"):
    dynamodb = boto3.resource(**boto_args)
    table = dynamodb.Table(tableName)

    if date == "all":
        ke = Key('GSI_1_PK').eq("shard#{}".format(shardid)) & Key('GSI_1_SK').begins_with(responsecode)
    else:
        ke = Key('GSI_1_PK').eq("shard#{}".format(shardid)) & Key('GSI_1_SK').begins_with(responsecode+"#"+date)

    response = table.query(
        IndexName='GSI_1',
        KeyConditionExpression=ke
        )

    print('Records with response code %s in the shardid %s = %s' %(responsecode, shardid, response['Count']))
    queue.put(response['Count'])