runway.cfngin.hooks.awslambda.deployment_package module

Deployment package.

class runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackage[source]

Bases: DelCachedPropMixin, Generic[_ProjectTypeVar]

AWS Lambda Deployment Package.

When interacting with subclass of this instance, it is recommended to only call the methods defined within this parent class. This ensures compatibility with the S3 object class that can be returned.

META_TAGS: ClassVar[dict[str, str]] = {'code_sha256': 'runway.cfngin:awslambda.code_sha256', 'compatible_architectures': 'runway.cfngin:awslambda.compatible_architectures', 'compatible_runtimes': 'runway.cfngin:awslambda.compatible_runtimes', 'license': 'runway.cfngin:awslambda.license', 'md5_checksum': 'runway.cfngin:awslambda.md5_checksum', 'runtime': 'runway.cfngin:awslambda.runtime', 'source_code.hash': 'runway.cfngin:awslambda.source_code.hash'}

Mapping of metadata to the tag-key is is stored in on the S3 object.

SIZE_EOCD: Final = 22

Size of a zip file’s End of Central Directory Record (empty zip).

ZIPFILE_PERMISSION_MASK: ClassVar[int] = 33488896

Mask to retrieve unix file permissions from the external attributes property of a zipfile.ZipInfo.

__init__(project: _ProjectTypeVar, usage_type: Literal['function', 'layer'] = 'function') None[source]

Instantiate class.

The provided .init() class method should be used in place of direct instantiation.

Parameters:
  • project – Project that is being built into a deployment package.

  • usage_type – How the deployment package can be used by AWS Lambda.

property archive_file: Path

Path to archive file.

Because the archive file path contains runtime, it’s use can cause a race condition or recursion error if used in some locations. If we removed runtime from the path we would not have a way to track changes to runtime which is more important than needing to be mindful of where this is used.

property bucket: Bucket

AWS S3 bucket where deployment package will be uploaded.

build() Path[source]

Build the deployment package.

build_tag_set(*, url_encoded: Literal[True] = True) str[source]
build_tag_set(*, url_encoded: Literal[False]) dict[str, str]
build_tag_set(*, url_encoded: bool = True) dict[str, str] | str

Build tag set to be applied to the S3 object.

Parameters:
  • layer – Tag the deployment package as a Lambda Layer or not.

  • url_encoded – Whether to return a dict or URL encoded query string.

property code_sha256: str

SHA256 of the archive file.

Returns:

Value to pass to CloudFormation AWS::Lambda::Version.CodeSha256.

Raises:

FileNotFoundError – Property accessed before archive file has been built.

property compatible_architectures: list[str] | None

List of compatible instruction set architectures.

property compatible_runtimes: list[str] | None

List of compatible runtimes.

delete() None[source]

Delete deployment package.

property exists: bool

Whether the deployment package exists.

property gitignore_filter: igittigitt.IgnoreParser | None

Filter to use when zipping dependencies.

This should be overridden by subclasses if a filter should be used.

classmethod init(project: _ProjectTypeVar, usage_type: Literal['function', 'layer'] = 'function') DeploymentPackage[_ProjectTypeVar][source]

Initialize deployment package.

This should be used in place of creating an instance of this class directly as it will automatically account for the S3 object already existing.

Parameters:
  • project – Project that is being built into a deployment package.

  • usage_type – How the deployment package can be used by AWS Lambda.

Returns:

Instance of generic S3 object class if S3 object exists else an instance of this class.

static insert_layer_dir(file_path: Path, relative_to: Path) Path[source]

Insert directory into local file path for layer archive.

If required, this should be overridden by a subclass for language specific requirements.

Parameters:
  • file_path – Path to local file.

  • relative_to – Path to a directory that the file_path will be relative to in the deployment package.

iterate_dependency_directory() Iterator[Path][source]

Iterate over the contents of the dependency directory.

If gitignore_filter is set, it will be used to exclude files.

property license: str | None

Software license for the project.

property md5_checksum: str

MD5 of the archive file.

Returns:

Value to pass as ContentMD5 when uploading to AWS S3.

Raises:

FileNotFoundError – Property accessed before archive file has been built.

property object_key: str

Key to use when upload object to AWS S3.

property object_version_id: str | None

S3 object version ID.

Returns:

The ID of the current object version. This will only have a value if versioning is enabled on the bucket.

project: _ProjectTypeVar

Project that is being built into a deployment package.

property runtime: str

Runtime of the deployment package.

upload(*, build: bool = True) None[source]

Upload deployment package.

Parameters:

build – If true, the deployment package will be built before before trying to upload it. If false, it must have already been built.

usage_type: Literal['function', 'layer']

How the deployment package can be used by AWS Lambda.

class runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackageS3Object[source]

Bases: DeploymentPackage[_ProjectTypeVar]

AWS Lambda Deployment Package.

This should not need to be subclassed as the interactions required should be universal.

project

Project that is being built into a deployment package.

build() Path[source]

Build the deployment package.

The object should already exist. This method only exists as a “placeholder” to match the parent class. If the object does not already exist, and error is raised.

Raises:

S3ObjectDoesNotExistError – The S3 object does not exist.

property code_sha256: str

SHA256 of the archive file.

Returns:

Value to pass to CloudFormation AWS::Lambda::Version.CodeSha256.

Raises:

RequiredTagNotFound – A required tag was not found.

property compatible_architectures: list[str] | None

List of compatible instruction set architectures.

property compatible_runtimes: list[str] | None

List of compatible runtimes.

delete() None[source]

Delete deployment package.

property exists: bool

Whether the S3 object exists.

property head: HeadObjectOutputTypeDef | None

Response from HeadObject API call.

property license: str | None

Software license for the project.

property md5_checksum: str

MD5 of the archive file.

Returns:

Value to pass as ContentMD5 when uploading to AWS S3.

Raises:

RequiredTagNotFoundError – A required tag was not found.

property object_tags: dict[str, str]

S3 object tags.

property object_version_id: str | None

S3 object version ID.

Returns:

The ID of the current object version. This will only have a value if versioning is enabled on the bucket.

property runtime: str

Runtime of the deployment package.

Raises:

RequiredTagNotFoundError – A required tag was not found.

update_tags() None[source]

Update tags of the S3 object.

upload(*, build: bool = True) None[source]

Upload deployment package.

The object should already exist. This method only exists as a “placeholder” to match the parent class. If the object does not already exist, and error is raised.

Parameters:

build – If true, the deployment package will be built before before trying to upload it. If false, it must have already been built.

Raises:

S3ObjectDoesNotExistError – The S3 object does not exist.