def query_table(table): """ Args: table: DynamoDB table object to query returns: items: items returned from the query """ kwargs = { "KeyConditionExpression": Key("pk").eq("bldVrsn0#"), "ProjectionExpression": "crtdDt, pckg, pckgVrsn, rqrmntsTxt", } items = query_till_end(table=table, kwargs=kwargs) return map_keys(items)
def query_table(table, python_version: str): """ Args: table: DynamoDB table object to query python_version: Version of python (e.g. p3.8, p3.9) returns: items: items returned from the query """ kwargs = { "KeyConditionExpression": Key("pk").eq(f"bldVrsn0#{python_version}"), "ProjectionExpression": "crtdDt, pckg, pckgVrsn, rqrmntsTxt", } items = query_till_end(table=table, kwargs=kwargs) return map_keys(items)
def query_table(region, table, pk): """ Args: table: DynamoDB table object to query region: region to query on returns: items: items returned from the query """ kwargs = { "KeyConditionExpression": Key("pk").eq(pk), "ProjectionExpression": "arn, pckgVrsn, dplySts, rqrmntsTxt, exDt", "FilterExpression": "attribute_exists(dplySts)", # don't get latest version } items = query_till_end(table=table, kwargs=kwargs) return map_keys(items)
def query_table(region: str, table: str, python_version: str) -> list: """ Args: table: DynamoDB table object to query region: region to query on python_version: version of python (e.g. p3.9, p3.8) returns: items: items returned from the query """ kwargs = { "IndexName": "deployed_in_region_by_python_version", "KeyConditionExpression": Key("rgn#PyVrsn").eq(f"{region}:{python_version}") & Key("dplySts").eq("latest"), "ProjectionExpression": "pckg, arn, pckgVrsn", } items = query_till_end(table=table, kwargs=kwargs) return map_keys(items)
def query_table(region, table): """ Args: table: DynamoDB table object to query region: region to query on returns: items: items returned from the query """ kwargs = { "IndexName": "deployed_in_region", "KeyConditionExpression": Key("rgn").eq(region) & Key("dplySts").eq("latest"), "ProjectionExpression": "pckg, arn, pckgVrsn", } items = query_till_end(table=table, kwargs=kwargs) return map_keys(items)
def main(event, context): """ Args: event.pathParameter.region: AWS region event.pathParameter.package: Python Package returns: api_response: Dictionary containing, region, package, arn and requirements.txt data """ dynamodb = boto3.resource("dynamodb") table = dynamodb.Table(os.environ["DB_NAME"]) region = event.get("pathParameters").get("region") package = event.get("pathParameters").get("package") pk = f"lyr#{region}.{package}" sk = "lyrVrsn0#" try: response = table.get_item( Key={ "pk": pk, "sk": sk }, AttributesToGet=["rgn", "pckg", "arn", "rqrmntsTxt", "pckgVrsn"], ) api_response = map_keys([response["Item"]])[0] except ClientError as e: logger.error({ "message": response["Error"]["Message"], "pk": pk, "sk": sk, }) api_response = {} except KeyError as e: # no item return api_response = {} return { "statusCode": 200, "body": json.dumps(api_response), }