You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python-lambda is a toolset for developing and deploying *serverless* Python code in AWS Lambda.
21
+
This is a toolset for developing and deploying *serverless* Python code in AWS Lambda.
22
+
23
+
.. Important::
19
24
20
-
Important
21
-
=======================
22
-
This is a FORK of the original Python-lambda package by Nick Ficano.
23
-
It will NOT be updated regularly and is frozen per our projects needs.
25
+
This is a FORK of Nick Ficano's `Python-lambda <https://pypi.python.org/pypi/python-lambda>`_
26
+
package. It will NOT be updated regularly and is frozen for the needs of projects at the
27
+
`4D Nucleome Data Coordination and Integration Center (4DN-DCIC)
28
+
<https://github.com/4dn-dcic>`_.
24
29
25
30
Description
26
31
===========
27
32
28
-
AWS Lambda is a service that allows you to write Python, Java, or Node.js code that gets executed in response to events like http requests or files uploaded to S3.
33
+
AWS Lambda is a service that allows you to write Python, Java, or Node.js code that
34
+
gets executed in response to events like http requests or files uploaded to S3.
35
+
36
+
Working with Lambda is relatively easy, but the process of bundling and deploying your code
37
+
is not as simple as it could be.
38
+
39
+
The *Python-Lambda* library takes away the guess work of developing your Python-Lambda
40
+
services by providing you a toolset to streamline the annoying parts.
41
+
42
+
Important Legal Notice
43
+
======================
29
44
30
-
Working with Lambda is relatively easy, but the process of bundling and deploying your code is not as simple as it could be.
45
+
The original `Python-lambda <https://pypi.python.org/pypi/python-lambda>`_ is licensed under
46
+
an ISC license. `The version of that license active at time of the fork is here
The *Python-Lambda* library takes away the guess work of developing your Python-Lambda services by providing you a toolset to streamline the annoying parts.
50
+
A permissive license lets people do anything with your code with proper attribution
51
+
and without warranty. The ISC license is functionally equivalent to the BSD 2-Clause
52
+
and MIT licenses, removing some language that is no longer necessary.
33
53
34
-
Requirements
35
-
============
54
+
Since our derivative work is covered under the MIT license, and on a theory
55
+
that the underlying license is equivalent to the MIT license,
56
+
we shorthand our licensing requirements as just "MIT" because that's more consistent
57
+
with how we describe licensing for other 4DN-DCIC software.
58
+
However, for the properly formal legal detail,
59
+
please refer to our actual `LICENSE <LICENSE>`_.
60
+
61
+
System Requirements
62
+
===================
36
63
37
64
* Python 3.6
38
65
* Pip (Any should work)
39
66
* Virtualenv (>=15.0.0)
40
-
* Virtualenvwrapper (>=4.7.1)
67
+
68
+
Setting Up a Virtual Environment (OPTIONAL)
69
+
===========================================
70
+
71
+
This is optional.
72
+
If you do not create a virtual environment, Poetry will make one for you.
73
+
But there are still good reasons you might want to make your own, so here
74
+
are three ways to do it:
75
+
76
+
* If you have virtualenvwrapper that knows to use Python 3.6::
77
+
78
+
mkvirtualenv myenv
79
+
80
+
* If you have virtualenv but not virtualenvwrapper, and you have python3.6 in your ``PATH``::
81
+
82
+
virtualenv myenv -p python3.6
83
+
84
+
* If you are using ``pyenv`` to control what environment you use::
85
+
86
+
pyenv exec python -m venv myenv
87
+
88
+
89
+
Installing Poetry in a Virtual Environment
90
+
==========================================
91
+
92
+
Once you have created a virtual environment, or have decided to just let Poetry handle that,
93
+
install with poetry::
94
+
95
+
poetry install
96
+
41
97
42
98
Getting Started
43
99
===============
44
100
45
-
Using this library is intended to be as straightforward as possible. Code for a very simple lambda used in the tests is reproduced below.
101
+
Using this library is intended to be as straightforward as possible.
102
+
Code for a very simple lambda used in the tests is reproduced below.
46
103
47
104
.. code:: python
48
105
@@ -57,11 +114,13 @@ Using this library is intended to be as straightforward as possible. Code for a
57
114
'description': 'Test lambda'
58
115
}
59
116
60
-
61
117
defhandler(event, context):
62
118
return'Hello! My input event is %s'% event
63
119
64
-
This code illustrates the two things required to create a lambda. The first is ``config``, which specifies metadata for AWS. One important thing to note in here is the ``role`` field. This must be a IAM role with Lambda permissions - the one in this example is ours. The second is the ``handler`` function. This is the actual code that is executed.
120
+
This code illustrates the two things required to create a lambda. The first is ``config``,
121
+
which specifies metadata for AWS. One important thing to note in here is the ``role`` field.
122
+
This must be a IAM role with Lambda permissions - the one in this example is ours.
123
+
The second is the ``handler`` function. This is the actual code that is executed.
65
124
66
125
Given this code in ``example_function.py`` you would deploy this function like so:
67
126
@@ -75,14 +134,34 @@ Given this code in ``example_function.py`` you would deploy this function like s
75
134
requirements_fpath='path/to/requirements',
76
135
extra_config={'optional_arguments_for': 'boto3'})
77
136
78
-
And that's it! You've deployed a simple lambda function. You can navigate to the AWS console to create a test event to trigger it or you can invoke it directly using Boto3.
137
+
And that's it! You've deployed a simple lambda function. You can navigate to the AWS
138
+
console to create a test event to trigger it or you can invoke it directly using Boto3.
79
139
80
140
Advanced Usage
81
141
==============
82
142
83
-
Many of the options specified in the above code block when it came to actually deploying the function are not used. These become more useful as you want to make more complicated lambda functions. The ideal way to incorporate dependencies into lambda functions is by providing a ``requirements.txt`` file. We rely on ``pip`` to install these packages and have found it to be very reliable. While it is also possible to specify local modules as well through ``package_objects``, doing so is not recommended because those modules must be specified at the top level of the repository in order to work out of the box. There is a comment on this topic in ``example_function_package.py`` with code on how to handle it.
143
+
Many of the options specified in the above code block when it came to actually
144
+
deploying the function are not used. These become more useful as you want to make more
145
+
complicated lambda functions. The ideal way to incorporate dependencies into lambda functions
146
+
is by providing a ``requirements.txt`` file. We rely on ``pip`` to install these packages
147
+
and have found it to be very reliable. While it is also possible to specify local modules
148
+
as well through ``package_objects``, doing so is not recommended because those modules
149
+
must be specified at the top level of the repository in order to work out of the box.
150
+
There is a comment on this topic in ``example_function_package.py``
151
+
with code on how to handle it.
84
152
85
153
Tests
86
154
========
87
155
88
-
Tests can be found in the ``test_aws_lambda.py``. Using the tests as a guide to develop your lambdas is probably a good idea. You can also see how to invoke the lambdas directly from Python (and interpret the response).
156
+
Tests can be found in the ``test_aws_lambda.py``. Using the tests as a guide to develop
157
+
your lambdas is probably a good idea. You can also see how to invoke the lambdas directly
158
+
from Python (and interpret the response). You can invoke all of this by just doing::
159
+
160
+
pytest
161
+
162
+
The usual ``pytest`` arguments are permited. For example, to invoke an individual test,
163
+
mention its name. To see verbose output, use ``-v``; or use ``-vv`` for extra-verbose output,
0 commit comments