runway.cfngin.hooks.awslambda.deployment_package module

Deployment package.

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

Bases: runway.mixins.DelCachedPropMixin, Generic[runway.cfngin.hooks.awslambda.deployment_package._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[Literal[22]] = 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: runway.cfngin.hooks.awslambda.deployment_package._ProjectTypeVar, usage_type: typing_extensions.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.

project: _ProjectTypeVar

Project that is being built into a deployment package.

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

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: runway.core.providers.aws.s3._bucket.Bucket

AWS S3 bucket where deployment package will be uploaded.

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: Optional[List[str]]

List of compatible instruction set architectures.

property compatible_runtimes: Optional[List[str]]

List of compatible runtimes.

property exists: bool

Whether the deployment package exists.

property gitignore_filter: Optional[igittigitt.IgnoreParser]

Filter to use when zipping dependencies.

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

property license: Optional[str]

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: Optional[str]

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.

build() Path[source]

Build the deployment package.

build_tag_set(*, url_encoded: typing_extensions.Literal[True] = True) str[source]
build_tag_set(*, url_encoded: typing_extensions.Literal[False] = True) Dict[str, str]
build_tag_set(*, url_encoded: bool = True) Union[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.

delete() None[source]

Delete deployment package.

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.

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.

classmethod init(project: runway.cfngin.hooks.awslambda.deployment_package._ProjectTypeVar, usage_type: typing_extensions.Literal[function, layer] = 'function') runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackage[runway.cfngin.hooks.awslambda.deployment_package._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.

__new__(**kwargs)
class runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackageS3Object[source]

Bases: runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackage[runway.cfngin.hooks.awslambda.deployment_package._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.

Type

_ProjectTypeVar

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: Optional[List[str]]

List of compatible instruction set architectures.

property compatible_runtimes: Optional[List[str]]

List of compatible runtimes.

property exists: bool

Whether the S3 object exists.

__init__(project: runway.cfngin.hooks.awslambda.deployment_package._ProjectTypeVar, usage_type: typing_extensions.Literal[function, layer] = 'function') None

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.

__new__(**kwargs)
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: runway.core.providers.aws.s3._bucket.Bucket

AWS S3 bucket where deployment package will be uploaded.

build_tag_set(*, url_encoded: bool = True) Union[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 gitignore_filter: Optional[igittigitt.IgnoreParser]

Filter to use when zipping dependencies.

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

property head: Optional[HeadObjectOutputTypeDef]

Response from HeadObject API call.

classmethod init(project: runway.cfngin.hooks.awslambda.deployment_package._ProjectTypeVar, usage_type: typing_extensions.Literal[function, layer] = 'function') runway.cfngin.hooks.awslambda.deployment_package.DeploymentPackage[runway.cfngin.hooks.awslambda.deployment_package._ProjectTypeVar]

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

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]

Iterate over the contents of the dependency directory.

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

property object_key: str

Key to use when upload object to AWS S3.

property license: Optional[str]

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: Optional[str]

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.

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.

delete() None[source]

Delete deployment package.

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.