def get(event, context): """ gets the information for the specific record in the dynamodb database """ if 'pathParameters' in event: parameters = event['pathParameters'] if 'sample' in parameters and 'job' in parameters: tm = TableManager() id = tm.generate_job_id(parameters['job'], parameters['sample']) table = tm.get_job_sample_state_table() result = table.query( KeyConditionExpression=Key('id').eq(id) ) if "Items" in result and len(result['Items']) > 0: return { "statusCode": 200, "headers": __HTTP_HEADERS__, "body": json.dumps(result['Items'][0]) } else: return { "statusCode": 404, "headers": __HTTP_HEADERS__, "body": json.dumps({"error": "no sample found with this identifier : {}".format( event['pathParameters']['sample'])}) } # invalid! return { 'statusCode': 503 }
def remove_sample_for_job(event, context): """ remove a sample from a stored job """ logger.info(event) if 'pathParameters' in event: parameters = event['pathParameters'] if 'sample' in parameters and 'job' in parameters: tm = TableManager() rid = tm.generate_job_id(parameters['job'], parameters['sample']) trktable = tm.get_job_sample_state_table() logger.info(f"generated id: {rid}") try: saved = trktable.delete_item(Key={ 'id': rid, 'job': parameters['job'] }) # save or update our item logger.info(saved) return { 'body': '', 'statusCode': 200, 'isBase64Encoded': False, 'headers': __HTTP_HEADERS__ } except Exception as e: traceback.print_exc() return { 'body': str(e), 'statusCode': 500, 'isBase64Encoded': False, 'headers': __HTTP_HEADERS__ } return {'statusCode': 503}