-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda.py
executable file
·133 lines (114 loc) · 3.13 KB
/
lambda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env -S poetry run python
import shutil
import click
from dotenv import load_dotenv
from werkit.orchestrator.deploy import (
deploy_orchestrator,
update_orchestrator_code,
)
load_dotenv()
BUILD_DIR = "build"
@click.group()
def cli():
pass
def _clean():
shutil.rmtree(BUILD_DIR, ignore_errors=True)
@cli.command()
def clean():
_clean()
def common_options(function):
function = click.option(
"--path-to-orchestrator-zip",
default="build/orchestrator-function.zip",
help="Orchestrator lambda zip function target location",
)(function)
function = click.option(
"--orchestrator-function-name",
required=True,
envvar="ORCHESTRATOR_FUNCTION_NAME",
show_envvar=True,
help="Name of the orchestrator lambda function",
)(function)
function = click.option(
"--region",
required=True,
envvar="AWS_REGION",
show_envvar=True,
help="AWS region to deploy to",
)(function)
function = click.option(
"--s3-code-bucket", default=None, help="S3 bucket where code is uploaded"
)(function)
function = click.option("--verbose", default=False, help="Enable verbose output")(
function
)
return function
def deploy_options(function):
function = click.option(
"--worker-function-name",
required=True,
help="Name of the lambda worker function invoked by orchestrator",
envvar="WORKER_FUNCTION_NAME",
show_envvar=True,
)(function)
function = click.option(
"--role",
required=True,
help="AWS Role for the orchestrator lambda function",
envvar="LAMBDA_ROLE",
show_envvar=True,
)(function)
function = click.option(
"--worker-timeout", default=600, help="Timeout for each worker function"
)(function)
function = click.option(
"--orchestrator-timeout",
default=600,
help="Timeout of the orchestrator lambda function",
)(function)
return function
@cli.command()
@common_options
@deploy_options
def deploy(
region,
path_to_orchestrator_zip,
orchestrator_function_name,
s3_code_bucket,
verbose,
role,
worker_function_name,
worker_timeout,
orchestrator_timeout,
):
_clean()
deploy_orchestrator(
aws_region=region,
build_dir=BUILD_DIR,
path_to_orchestrator_zip=path_to_orchestrator_zip,
orchestrator_function_name=orchestrator_function_name,
role=role,
orchestrator_timeout=orchestrator_timeout,
worker_function_name=worker_function_name,
worker_timeout=worker_timeout,
s3_code_bucket=s3_code_bucket,
)
@cli.command()
@common_options
def update_code(
region,
path_to_orchestrator_zip,
orchestrator_function_name,
s3_code_bucket,
verbose,
):
_clean()
update_orchestrator_code(
aws_region=region,
build_dir=BUILD_DIR,
path_to_orchestrator_zip=path_to_orchestrator_zip,
orchestrator_function_name=orchestrator_function_name,
s3_code_bucket=s3_code_bucket,
)
if __name__ == "__main__":
cli()