runway.cfngin.hooks.awslambda.base_classes module

Base classes.

class runway.cfngin.hooks.awslambda.base_classes.Project[source]

Bases: Generic[runway.cfngin.hooks.awslambda.base_classes._AwsLambdaHookArgsTypeVar_co]

Project containing source code for an AWS Lambda Function.

DEFAULT_CACHE_DIR_NAME: ClassVar[str] = 'cache'

Name of the default cache directory.

__init__(args: runway.cfngin.hooks.awslambda.base_classes._AwsLambdaHookArgsTypeVar_co, context: runway.context.CfnginContext) None[source]

Instantiate class.

Parameters
  • args – Parsed hook arguments.

  • context – Context object.

args: _AwsLambdaHookArgsTypeVar_co

Parsed hook arguments.

ctx: CfnginContext

CFNgin context object.

property build_directory: pathlib.Path

Directory being used to build deployment package.

property cache_dir: Optional[pathlib.Path]

Directory where a dependency manager’s cache data will be stored.

Returns

Explicit cache directory if provided or default cache directory if it is not provided. If configured to not use cache, will always be None.

property compatible_architectures: Optional[List[str]]

List of compatible instruction set architectures.

property compatible_runtimes: Optional[List[str]]

List of compatible runtimes.

Value should be valid Lambda Function runtimes (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

Raises

ValueError – Defined or detected runtime is not in the list of compatible runtimes.

property dependency_directory: pathlib.Path

Directory to use as the target of pip install --target.

property license: Optional[str]

Software license for the project.

Can be any of the following:

  • A SPDX license identifier (e.g. MIT).

  • The URL of a license hosted on the internet (e.g. https://opensource.org/licenses/MIT).

  • The full text of the license.

property metadata_files: Tuple[pathlib.Path, ...]

Project metadata files (e.g. project.json, pyproject.toml).

property runtime: str

runtime of the build system.

Value should be a valid Lambda Function runtime (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).

This property can be overwritten by subclasses when runtime can be determined through additional means.

property source_code: runway.cfngin.hooks.awslambda.source_code.SourceCode

Project source code.

Lazy load source code object. Extends gitignore as needed.

property project_root: pathlib.Path

Root directory of the project.

The top-level directory containing the source code and all configuration/metadata files (e.g. pyproject.toml, package.json).

The project root can be different from the source code directory but, if they are different, the project root should contain the source code directory. If it does not, the source code directory will be always be used.

The primary use case for this property is to allow configuration files to exist outside of the source code directory. The project_type can and should rely on the value of this property when determining the type.

property project_type: str

Type of project (e.g. poetry, yarn).

This should be considered more of a “subtype” as the subclass should distinguish project language. The value of this property should reflect the project/dependency management tool used within the project.

The value of this property should be calculated without initializing other properties (e.g. source_code) except for project_root so that it can be used in their initialization process.

property supported_metadata_files: Set[str]

Names of all supported metadata files.

Returns

Set of file names - not paths.

cleanup() None[source]

Cleanup project files at the end of execution.

If any cleanup is needed (e.g. removal of temporary dependency directory) it should be implimented here. Hook’s should call this method in a finally block to ensure it is run even if the rest of the hook encountered an error.

cleanup_on_error() None[source]

Cleanup project files when an error occurs.

This will be run before self.cleanup() if an error has occurred.

Hooks should call this method in an except block and reraise the error afterward.

install_dependencies() None[source]

Install project dependencies.

Arguments/options should be read from the args attribute of this object instead of being passed into the method call. The method itself only exists for timing and filling in custom handling that is required for each project type.

__new__(**kwargs)
class runway.cfngin.hooks.awslambda.base_classes.AwsLambdaHook[source]

Bases: runway.cfngin.hooks.protocols.CfnginHookProtocol, Generic[runway.cfngin.hooks.awslambda.base_classes._ProjectTypeVar]

Base class for AWS Lambda hooks.

BUILD_LAYER: ClassVar[bool] = False

Flag to denote if the hook creates a Lambda Function or Layer deployment package.

args: AwsLambdaHookArgs

Parsed hook arguments.

__init__(context: runway.context.CfnginContext, **_kwargs: Any) None[source]

Instantiate class.

This method should be overridden by subclasses. This is required to set the value of the args attribute.

Parameters

context – CFNgin context object (passed in by CFNgin).

ctx: CfnginContext

CFNgin context object.

property deployment_package: DeploymentPackage[_ProjectTypeVar]

AWS Lambda deployment package.

property project: runway.cfngin.hooks.awslambda.base_classes._ProjectTypeVar

Project being deployed as an AWS Lambda Function.

__new__(**kwargs)
build_response(stage: Literal['deploy']) runway.cfngin.hooks.awslambda.models.responses.AwsLambdaHookDeployResponse[source]
build_response(stage: Literal['destroy']) Optional[BaseModel]
build_response(stage: Literal['plan']) runway.cfngin.hooks.awslambda.models.responses.AwsLambdaHookDeployResponse

Build response object that will be returned by this hook.

Parameters

stage – The current stage being executed by the hook.

cleanup() None[source]

Cleanup temporary files at the end of execution.

If any cleanup is needed (e.g. removal of temporary dependency directory) it should be implimented here. A Hook’s stage methods should call this method in a finally block to ensure it is run even if the rest of the hook encountered an error.

Example

def pre_deploy(self) -> Any:
    try:
        pass  # primary logic
    except BaseException:
        self.cleanup_on_error()
        raise
    finally:
        self.cleanup()
cleanup_on_error() None[source]

Cleanup temporary files when an error occurs.

This will be run before self.cleanup() if an error has occurred.

A Hook’s stage method should call this method in an except block and reraise the error afterward.

Example

def pre_deploy(self) -> Any:
    try:
        pass  # primary logic
    except BaseException:
        self.cleanup_on_error()
        raise
    finally:
        self.cleanup()
plan() AwsLambdaHookDeployResponseTypedDict[source]

Run during the plan stage.

post_deploy() Any[source]

Run during the post_deploy stage.

post_destroy() Any[source]

Run during the post_destroy stage.

pre_deploy() Any[source]

Run during the pre_deploy stage.

pre_destroy() Any[source]

Run during the pre_destroy stage.