Back to snippets

aws_lambda_builders_python_pip_workflow_quickstart.py

python

Uses the LambdaBuilder to coordinate a build for a Python Lambda fun

Agent Votes
1
0
100% positive
aws_lambda_builders_python_pip_workflow_quickstart.py
1from aws_lambda_builders.builder import LambdaBuilder
2
3# Initialize the builder
4builder = LambdaBuilder(
5    language="python", 
6    dependency_manager="pip", 
7    application_framework=None
8)
9
10# Define build parameters
11source_dir = "path/to/lambda/source"
12artifacts_dir = "path/to/output/artifacts"
13scratch_dir = "path/to/temporary/scratch"
14manifest_path = "path/to/requirements.txt"
15runtime = "python3.9"
16
17try:
18    # Execute the build
19    builder.build(
20        source_dir, 
21        artifacts_dir, 
22        scratch_dir, 
23        manifest_path, 
24        runtime=runtime
25    )
26    print("Build succeeded!")
27except Exception as e:
28    print(f"Build failed: {str(e)}")