forked from nficano/python-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda
More file actions
executable file
·151 lines (131 loc) · 4.77 KB
/
lambda
File metadata and controls
executable file
·151 lines (131 loc) · 4.77 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import click
import aws_lambda
import logging
CURRENT_DIR = os.getcwd()
logging.getLogger('pip').setLevel(logging.CRITICAL)
@click.group()
def cli():
pass
@click.command(help='Create a new function for Lambda.')
@click.option(
'--minimal', default=False, is_flag=True,
help='Exclude any unnecessary template files',
)
@click.argument(
'folder', nargs=-1,
type=click.Path(file_okay=False, writable=True),
)
def init(folder, minimal):
path = CURRENT_DIR
if len(folder) > 0:
path = os.path.join(CURRENT_DIR, *folder)
if not os.path.exists(path):
os.makedirs(path)
aws_lambda.init(path, minimal=minimal)
@click.command(help='Bundles package for deployment.')
@click.option(
'--use-requirements', default=False, is_flag=True,
help='Install all packages defined in requirements.txt',
)
@click.option(
'--local-package', default=None, type=click.Path(),
help='Install local package as well.', multiple=True,
)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
def build(use_requirements, local_package, config_file_path=None):
aws_lambda.build(CURRENT_DIR, use_requirements, local_package, config_file_path)
@click.command(help='Run a local test of your function.')
@click.option('--event-file', default=None, help='Alternate event file.')
@click.option('--verbose', '-v', is_flag=True)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
def invoke(event_file, verbose, config_file_path):
aws_lambda.invoke(CURRENT_DIR, event_file, verbose, config_file_path)
@click.command(help='Register and deploy your code to lambda.')
@click.option(
'--use-requirements', default=False, is_flag=True,
help='Install all packages defined in requirements.txt',
)
@click.option(
'--local-package', default=None, type=click.Path(),
help='Install local package as well.', multiple=True,
)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
@click.option(
'--aws-profile', default=None, type=click.STRING,
help='AWS profile name.', multiple=False
)
def deploy(use_requirements, local_package, config_file_path, aws_profile):
aws_lambda.deploy(CURRENT_DIR, use_requirements, local_package, config_file_path=config_file_path,
aws_profile=aws_profile)
@click.command(help='Deploy your code to S3 and register to lambda.')
@click.option(
'--use-requirements', default=False, is_flag=True,
help='Install all packages defined in requirements.txt',
)
@click.option(
'--local-package', default=None, type=click.Path(),
help='Install local package as well.', multiple=True,
)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
@click.option(
'--aws-profile', default=None, type=click.STRING,
help='AWS profile name.', multiple=False
)
def deploy_s3(use_requirements, local_package, config_file_path, aws_profile):
aws_lambda.deploy(CURRENT_DIR, use_requirements, local_package, upload_to_s3=True,
config_file_path=config_file_path, aws_profile=aws_profile)
@click.command(help='Upload your lambda to S3.')
@click.option(
'--use-requirements', default=False, is_flag=True,
help='Install all packages defined in requirements.txt',
)
@click.option(
'--local-package', default=None, type=click.Path(),
help='Install local package as well.', multiple=True,
)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
@click.option(
'--aws-profile', default=None, type=click.STRING,
help='AWS profile name.', multiple=False
)
def upload(use_requirements, local_package, config_file_path, aws_profile):
aws_lambda.upload(CURRENT_DIR, use_requirements, local_package, config_file_path=config_file_path,
aws_profile=aws_profile)
@click.command(help='Delete old versions of your functions')
@click.option(
'--keep-last', type=int,
prompt='Please enter the number of recent versions to keep',
)
@click.option(
'--config-file-path', default=None, type=click.Path(),
help='Path to custom config.yaml file', multiple=False
)
def cleanup(keep_last, config_file_path):
aws_lambda.cleanup_old_versions(CURRENT_DIR, keep_last, config_file_path=config_file_path)
if __name__ == '__main__':
cli.add_command(init)
cli.add_command(invoke)
cli.add_command(deploy)
cli.add_command(deploy_s3)
cli.add_command(upload)
cli.add_command(build)
cli.add_command(cleanup)
cli()