"""Lambda function module.""" from src.config import logger from constants import general from constants import errors from src import lambda_exceptions from src import s3 from src import status from src.connectors import ows_assets def handler(event, context): """Lambda entry point.""" bucket, key = event.get('bucket'), event.get('key') if not s3.object_exists(bucket, key): lambda_exceptions.notify_and_raise( general.LAMBDA_NAME, general.UPLOAD_ERROR_STATUS, errors.S3_FILE_NOT_FOUND_CODE, key, bucket, { 'key': key, 'bucket': bucket}) try: asset_upload_type = ows_assets.get_asset_upload_type(key) status.send_general_status( general.LAMBDA_NAME, general.ENCODING_ROUTE_COMPLETE_STATUS, key, input_params={**event, 'asset_upload_type': asset_upload_type}, bucket=bucket) return { 'bucket': bucket, 'key': key, 'asset_upload_type': asset_upload_type } except lambda_exceptions.AssetNotFoundException: return { 'bucket': bucket, 'key': key, 'stop_processing': True } except lambda_exceptions.LoggedException: raise except Exception as e: logger.exception(str(e)) lambda_exceptions.notify_and_raise( general.LAMBDA_NAME, general.ENCODING_ROUTE_ERROR_STATUS, errors.ASSET_ROUTING_ERROR_CODE, key, bucket, { 'message': str(e)})