1
1
python-lambda-local
2
2
===================
3
3
4
+ |Join the chat at https://gitter.im/HDE/python-lambda-local | |wercker
5
+ status | |PyPI version |
6
+
4
7
Run lambda function on local machine
5
8
6
9
Prepare development environment
7
10
-------------------------------
8
11
9
- Please use a newly created virtualenv for python2.7 .
12
+ Please use a newly created virtualenv of Python 2.7 or Python 3.6 .
10
13
11
14
Installation
12
15
------------
@@ -15,8 +18,7 @@ Within virtualenv, run the following command.
15
18
16
19
.. code :: bash
17
20
18
- $ cd $PROJECT_ROOT
19
- $ pip install ./
21
+ $ pip install python-lambda-local
20
22
21
23
This will install the package with name ``python-lambda-local `` in the
22
24
virtualenv. Now you can use the command ``python-lambda-local `` to run
@@ -30,7 +32,7 @@ Run ``python-lambda-local -h`` to see the help.
30
32
::
31
33
32
34
usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
33
- [-t TIMEOUT]
35
+ [-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]
34
36
FILE EVENT
35
37
36
38
Run AWS Lambda function written in Python on local machine.
@@ -47,6 +49,10 @@ Run ``python-lambda-local -h`` to see the help.
47
49
Lambda function handler name. Default: "handler".
48
50
-t TIMEOUT, --timeout TIMEOUT
49
51
Seconds until lambda function timeout. Default: 3
52
+ -a ARN_STRING, --arn-string ARN_STRING
53
+ arn string for function
54
+ -v VERSION_NAME, --version-name VERSION_NAME
55
+ function version name
50
56
51
57
Prepare development directory
52
58
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -60,49 +66,50 @@ Suppose your project directory is like this:
60
66
61
67
├── event.json
62
68
├── lib
63
- │ ├── rx
64
- │ │ ├── abstractobserver.py
65
- │ │ ├── ... (package content of rx)
69
+ │ ├── rx
70
+ │ │ ├── abstractobserver.py
71
+ │ │ ├── ... (package content of rx)
66
72
...
67
- │ │ └── testscheduler.py
68
- │ └── Rx-1.2.3.dist-info
69
- │ ├── DESCRIPTION.rst
70
- │ ├── METADATA
71
- │ ├── metadata.json
72
- │ ├── pbr.json
73
- │ ├── RECORD
74
- │ ├── top_level.txt
75
- │ ├── WHEEL
76
- │ └── zip-safe
73
+ │ │ └── testscheduler.py
74
+ │ └── Rx-1.2.3.dist-info
75
+ │ ├── DESCRIPTION.rst
76
+ │ ├── METADATA
77
+ │ ├── metadata.json
78
+ │ ├── pbr.json
79
+ │ ├── RECORD
80
+ │ ├── top_level.txt
81
+ │ ├── WHEEL
82
+ │ └── zip-safe
77
83
└── test.py
78
84
79
- In the handler's code is in ``test.py `` and the function name of the
85
+ The handler's code is in ``test.py `` and the function name of the
80
86
handler is ``handler ``. The source depends on 3rd party library ``rx ``
81
- and it is install in the directory ``lib ``. The test event of json
87
+ and it is installed in the directory ``lib ``. The test event in json
82
88
format is in ``event.json `` file.
83
89
84
90
Content of ``test.py ``:
85
91
^^^^^^^^^^^^^^^^^^^^^^^
86
92
87
93
.. code :: python
88
94
95
+ from __future__ import print_function
89
96
from rx import Observable
90
97
91
98
92
99
def handler (event , context ):
93
- xs = Observable.from_([ 1 , 2 , 3 , 4 , 5 , 6 ] )
100
+ xs = Observable.from_(range (event[ ' answer ' ]) )
94
101
ys = xs.to_blocking()
95
- zs = (x* x for x in ys if x > 3 )
102
+ zs = (x* x for x in ys if x % 7 == 0 )
96
103
for x in zs:
97
- print x
104
+ print (x)
98
105
99
106
Content of ``event.json ``:
100
107
^^^^^^^^^^^^^^^^^^^^^^^^^^
101
108
102
109
.. code :: json
103
110
104
111
{
105
- "key " : " value "
112
+ "answer " : 42
106
113
}
107
114
108
115
Run the lambda function
@@ -119,10 +126,22 @@ The output will be like:
119
126
120
127
::
121
128
122
- [INFO 2015-10-16 18:21:14,774] Event: {'key': 'value'}
123
- [INFO 2015-10-16 18:21:14,774] START RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
124
- 16
125
- 25
126
- 36
127
- [INFO 2015-10-16 18:21:14,775] END RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
128
- [INFO 2015-10-16 18:21:14,775] RESULT: None
129
+ [root - INFO - 2017-04-19 12:39:05,512] Event: {u'answer': 42}
130
+ [root - INFO - 2017-04-19 12:39:05,512] START RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
131
+ 0
132
+ 49
133
+ 196
134
+ 441
135
+ 784
136
+ 1225
137
+ [root - INFO - 2017-04-19 12:39:05,515] END RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
138
+ [root - INFO - 2017-04-19 12:39:05,515] RESULT:
139
+ None
140
+ [root - INFO - 2017-04-19 12:39:05,515] REPORT RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1 Duration: 2.27 ms
141
+
142
+ .. |Join the chat at https://gitter.im/HDE/python-lambda-local | image :: https://badges.gitter.im/Join%20Chat.svg
143
+ :target: https://gitter.im/HDE/python-lambda-local?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
144
+ .. |wercker status | image :: https://app.wercker.com/status/04f5bc5b7de3d5c6f13eb5b871035226/s
145
+ :target: https://app.wercker.com/project/bykey/04f5bc5b7de3d5c6f13eb5b871035226
146
+ .. |PyPI version | image :: https://badge.fury.io/py/python-lambda-local.svg
147
+ :target: https://badge.fury.io/py/python-lambda-local
0 commit comments