Source code for aws_lbd_art_builder_core.layer.upload
# -*- coding: utf-8 -*-"""Lambda layer S3 upload — Step 3 of the layer workflow.Uploads the packaged ``layer.zip`` to a staging location in S3 where thepublish step can pick it up to create a Lambda layer version.**Why store manifest_md5 in S3 metadata?**The publish step needs to verify that the ``layer.zip`` sitting in S3 wasactually built from the *current* dependency manifest on disk. Without thischeck, a stale zip from a previous build could be published by accident.By embedding the manifest MD5 at upload time and comparing it at publishtime, we get a cheap consistency gate."""importtypingasTfrompathlibimportPathfrom..typehintimportT_PRINTERfrom..constantsimportS3MetadataKeyEnumfrom..importsimportS3Pathfrom.foundationimportLayerManifestManagerifT.TYPE_CHECKING:# pragma: no coverfrommypy_boto3_s3importS3Client
[docs]defupload_layer_zip_to_s3(s3_client:"S3Client",path_pyproject_toml:Path,s3dir_lambda:"S3Path",path_manifest:Path,verbose:bool=True,printer:T_PRINTER=print,):""" Upload Lambda layer zip file to S3 staging location. :param s3_client: Configured boto3 S3 client :param path_pyproject_toml: Path to pyproject.toml (determines project root and zip location) :param s3dir_lambda: S3 directory path where Lambda artifacts are stored :param path_manifest: Path to the dependency manifest file (e.g. requirements.txt, uv.lock) :param verbose: If True, shows detailed upload progress :param printer: Function to handle progress messages """ifverbose:printer("--- Uploading Lambda Layer zip to S3 ...")manifest_manager=LayerManifestManager(path_pyproject_toml=path_pyproject_toml,s3dir_lambda=s3dir_lambda,path_manifest=path_manifest,s3_client=s3_client,printer=printer,)path_layer_zip=manifest_manager.path_layout.path_build_lambda_layer_zips3path=manifest_manager.s3_layout.s3path_temp_layer_zipprinter(f"upload from {path_layer_zip} to {s3path.uri}")printer(f"preview at {s3path.console_url}")s3path.upload_file(path=path_layer_zip,overwrite=True,extra_args={"ContentType":"application/zip","Metadata":{S3MetadataKeyEnum.manifest_md5.value:manifest_manager.manifest_md5,},},bsm=s3_client,)