@@ -8,15 +8,14 @@ Run lambda function on local machine
8
8
9
9
## Prepare development environment
10
10
11
- Please use a newly created virtualenv for python2.7 .
11
+ Please use a newly created virtualenv of Python 2.7 or Python 3.6 .
12
12
13
13
## Installation
14
14
15
15
Within virtualenv, run the following command.
16
16
17
17
``` bash
18
- $ cd $PROJECT_ROOT
19
- $ pip install ./
18
+ $ pip install python-lambda-local
20
19
```
21
20
22
21
This will install the package with name ` python-lambda-local ` in the virtualenv.
@@ -28,7 +27,7 @@ Run `python-lambda-local -h` to see the help.
28
27
29
28
```
30
29
usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
31
- [-t TIMEOUT]
30
+ [-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]
32
31
FILE EVENT
33
32
34
33
Run AWS Lambda function written in Python on local machine.
@@ -45,6 +44,10 @@ optional arguments:
45
44
Lambda function handler name. Default: "handler".
46
45
-t TIMEOUT, --timeout TIMEOUT
47
46
Seconds until lambda function timeout. Default: 3
47
+ -a ARN_STRING, --arn-string ARN_STRING
48
+ arn string for function
49
+ -v VERSION_NAME, --version-name VERSION_NAME
50
+ function version name
48
51
```
49
52
50
53
### Prepare development directory
@@ -73,29 +76,30 @@ Suppose your project directory is like this:
73
76
└── test.py
74
77
```
75
78
76
- In the handler's code is in ` test.py ` and the function name of the handler is ` handler ` .
77
- The source depends on 3rd party library ` rx ` and it is install in the directory ` lib ` .
78
- The test event of json format is in ` event.json ` file.
79
+ The handler's code is in ` test.py ` and the function name of the handler is ` handler ` .
80
+ The source depends on 3rd party library ` rx ` and it is installed in the directory ` lib ` .
81
+ The test event in json format is in ` event.json ` file.
79
82
80
83
#### Content of ` test.py ` :
81
84
82
85
``` python
86
+ from __future__ import print_function
83
87
from rx import Observable
84
88
85
89
86
90
def handler (event , context ):
87
- xs = Observable.from_([ 1 , 2 , 3 , 4 , 5 , 6 ] )
91
+ xs = Observable.from_(range (event[ ' answer ' ]) )
88
92
ys = xs.to_blocking()
89
- zs = (x* x for x in ys if x > 3 )
93
+ zs = (x* x for x in ys if x % 7 == 0 )
90
94
for x in zs:
91
- print x
95
+ print (x)
92
96
```
93
97
94
98
#### Content of ` event.json ` :
95
99
96
100
``` json
97
101
{
98
- "key " : " value "
102
+ "answer " : 42
99
103
}
100
104
```
101
105
@@ -110,11 +114,16 @@ python-lambda-local -l lib/ -f handler -t 5 test.py event.json
110
114
The output will be like:
111
115
112
116
```
113
- [INFO 2015-10-16 18:21:14,774] Event: {'key': 'value'}
114
- [INFO 2015-10-16 18:21:14,774] START RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
115
- 16
116
- 25
117
- 36
118
- [INFO 2015-10-16 18:21:14,775] END RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
119
- [INFO 2015-10-16 18:21:14,775] RESULT: None
117
+ [root - INFO - 2017-04-19 12:39:05,512] Event: {u'answer': 42}
118
+ [root - INFO - 2017-04-19 12:39:05,512] START RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
119
+ 0
120
+ 49
121
+ 196
122
+ 441
123
+ 784
124
+ 1225
125
+ [root - INFO - 2017-04-19 12:39:05,515] END RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
126
+ [root - INFO - 2017-04-19 12:39:05,515] RESULT:
127
+ None
128
+ [root - INFO - 2017-04-19 12:39:05,515] REPORT RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1 Duration: 2.27 ms
120
129
```
0 commit comments