runway.cfngin.hooks.awslambda.base_classes module¶
Base classes.
- class runway.cfngin.hooks.awslambda.base_classes.AwsLambdaHook[source]¶
Bases:
CfnginHookProtocol
,Generic
[_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.
- __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).
- build_response(stage: Literal['deploy']) AwsLambdaHookDeployResponse [source]¶
- build_response(stage: Literal['destroy']) BaseModel | None
- build_response(stage: Literal['plan']) 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()
- ctx: CfnginContext¶
CFNgin context object.
- property deployment_package: DeploymentPackage[_ProjectTypeVar]¶
AWS Lambda deployment package.
- plan() AwsLambdaHookDeployResponseTypedDict [source]¶
Run during the plan stage.
- property project: _ProjectTypeVar¶
Project being deployed as an AWS Lambda Function.
- class runway.cfngin.hooks.awslambda.base_classes.Project[source]¶
Bases:
Generic
[_AwsLambdaHookArgsTypeVar_co
]Project containing source code for an AWS Lambda Function.
- __init__(args: _AwsLambdaHookArgsTypeVar_co, context: runway.context.CfnginContext) None [source]¶
Instantiate class.
- Parameters:
args – Parsed hook arguments.
context – Context object.
- args: _AwsLambdaHookArgsTypeVar_co¶
Parsed hook arguments.
- property build_directory: Path¶
Directory being used to build deployment package.
- property cache_dir: Path | None¶
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
.
- 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.
- property compatible_architectures: list[str] | None¶
List of compatible instruction set architectures.
- property compatible_runtimes: list[str] | None¶
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.
- ctx: CfnginContext¶
CFNgin context object.
- property dependency_directory: Path¶
Directory to use as the target of
pip install --target
.
- 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.
- property license: str | None¶
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[Path, ...]¶
Project metadata files (e.g.
project.json
,pyproject.toml
).
- property project_root: 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 forproject_root
so that it can be used in their initialization process.
- 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: SourceCode¶
Project source code.
Lazy load source code object. Extends gitignore as needed.