Skip to content

Commit

Permalink
Merge pull request #11 from HDE/master
Browse files Browse the repository at this point in the history
Release v0.1.4 .
  • Loading branch information
yxd-hde authored Apr 19, 2017
2 parents 78f0edd + 04b62dd commit 9bcdd5b
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 67 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ Version 0.1.3
-------------

- Exit with non-zero code when execution of function fails.

Version 0.1.4
-------------

- Support Python 3.6.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 HDE, Inc.
Copyright (c) 2015-2017 HDE, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

[![Join the chat at https://gitter.im/HDE/python-lambda-local](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/HDE/python-lambda-local?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![wercker status](https://app.wercker.com/status/04f5bc5b7de3d5c6f13eb5b871035226/s "wercker status")](https://app.wercker.com/project/bykey/04f5bc5b7de3d5c6f13eb5b871035226)
[![PyPI version](https://badge.fury.io/py/python-lambda-local.svg)](https://badge.fury.io/py/python-lambda-local)

Run lambda function on local machine

## Prepare development environment

Please use a newly created virtualenv for python2.7.
Please use a newly created virtualenv of Python 2.7 or Python 3.6 .

## Installation

Within virtualenv, run the following command.

``` bash
$ cd $PROJECT_ROOT
$ pip install ./
$ pip install python-lambda-local
```

This will install the package with name `python-lambda-local` in the virtualenv.
Expand All @@ -27,7 +27,7 @@ Run `python-lambda-local -h` to see the help.

```
usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
[-t TIMEOUT]
[-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]
FILE EVENT
Run AWS Lambda function written in Python on local machine.
Expand All @@ -44,6 +44,10 @@ optional arguments:
Lambda function handler name. Default: "handler".
-t TIMEOUT, --timeout TIMEOUT
Seconds until lambda function timeout. Default: 3
-a ARN_STRING, --arn-string ARN_STRING
arn string for function
-v VERSION_NAME, --version-name VERSION_NAME
function version name
```

### Prepare development directory
Expand Down Expand Up @@ -72,29 +76,30 @@ Suppose your project directory is like this:
└── test.py
```

In the handler's code is in `test.py` and the function name of the handler is `handler`.
The source depends on 3rd party library `rx` and it is install in the directory `lib`.
The test event of json format is in `event.json` file.
The handler's code is in `test.py` and the function name of the handler is `handler`.
The source depends on 3rd party library `rx` and it is installed in the directory `lib`.
The test event in json format is in `event.json` file.

#### Content of `test.py`:

``` python
from __future__ import print_function
from rx import Observable


def handler(event, context):
xs = Observable.from_([1, 2, 3, 4, 5, 6])
xs = Observable.from_(range(event['answer']))
ys = xs.to_blocking()
zs = (x*x for x in ys if x > 3)
zs = (x*x for x in ys if x % 7 == 0)
for x in zs:
print x
print(x)
```

#### Content of `event.json`:

``` json
{
"key": "value"
"answer": 42
}
```

Expand All @@ -109,11 +114,16 @@ python-lambda-local -l lib/ -f handler -t 5 test.py event.json
The output will be like:

```
[INFO 2015-10-16 18:21:14,774] Event: {'key': 'value'}
[INFO 2015-10-16 18:21:14,774] START RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
16
25
36
[INFO 2015-10-16 18:21:14,775] END RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
[INFO 2015-10-16 18:21:14,775] RESULT: None
[root - INFO - 2017-04-19 12:39:05,512] Event: {u'answer': 42}
[root - INFO - 2017-04-19 12:39:05,512] START RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
0
49
196
441
784
1225
[root - INFO - 2017-04-19 12:39:05,515] END RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
[root - INFO - 2017-04-19 12:39:05,515] RESULT:
None
[root - INFO - 2017-04-19 12:39:05,515] REPORT RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1 Duration: 2.27 ms
```
79 changes: 49 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
python-lambda-local
===================

|Join the chat at https://gitter.im/HDE/python-lambda-local| |wercker
status| |PyPI version|

Run lambda function on local machine

Prepare development environment
-------------------------------

Please use a newly created virtualenv for python2.7.
Please use a newly created virtualenv of Python 2.7 or Python 3.6 .

Installation
------------
Expand All @@ -15,8 +18,7 @@ Within virtualenv, run the following command.

.. code:: bash
$ cd $PROJECT_ROOT
$ pip install ./
$ pip install python-lambda-local
This will install the package with name ``python-lambda-local`` in the
virtualenv. Now you can use the command ``python-lambda-local`` to run
Expand All @@ -30,7 +32,7 @@ Run ``python-lambda-local -h`` to see the help.
::

usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
[-t TIMEOUT]
[-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]
FILE EVENT

Run AWS Lambda function written in Python on local machine.
Expand All @@ -47,6 +49,10 @@ Run ``python-lambda-local -h`` to see the help.
Lambda function handler name. Default: "handler".
-t TIMEOUT, --timeout TIMEOUT
Seconds until lambda function timeout. Default: 3
-a ARN_STRING, --arn-string ARN_STRING
arn string for function
-v VERSION_NAME, --version-name VERSION_NAME
function version name

Prepare development directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -60,49 +66,50 @@ Suppose your project directory is like this:

├── event.json
├── lib
├── rx
├── abstractobserver.py
├── ... (package content of rx)
   ├── rx
   │   ├── abstractobserver.py
   │   ├── ... (package content of rx)
...
└── testscheduler.py
└── Rx-1.2.3.dist-info
├── DESCRIPTION.rst
├── METADATA
├── metadata.json
├── pbr.json
├── RECORD
├── top_level.txt
├── WHEEL
└── zip-safe
   │   └── testscheduler.py
   └── Rx-1.2.3.dist-info
   ├── DESCRIPTION.rst
   ├── METADATA
   ├── metadata.json
   ├── pbr.json
   ├── RECORD
   ├── top_level.txt
   ├── WHEEL
   └── zip-safe
└── test.py

In the handler's code is in ``test.py`` and the function name of the
The handler's code is in ``test.py`` and the function name of the
handler is ``handler``. The source depends on 3rd party library ``rx``
and it is install in the directory ``lib``. The test event of json
and it is installed in the directory ``lib``. The test event in json
format is in ``event.json`` file.

Content of ``test.py``:
^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
from __future__ import print_function
from rx import Observable
def handler(event, context):
xs = Observable.from_([1, 2, 3, 4, 5, 6])
xs = Observable.from_(range(event['answer']))
ys = xs.to_blocking()
zs = (x*x for x in ys if x > 3)
zs = (x*x for x in ys if x % 7 == 0)
for x in zs:
print x
print(x)
Content of ``event.json``:
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: json
{
"key": "value"
"answer": 42
}
Run the lambda function
Expand All @@ -119,10 +126,22 @@ The output will be like:

::

[INFO 2015-10-16 18:21:14,774] Event: {'key': 'value'}
[INFO 2015-10-16 18:21:14,774] START RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
16
25
36
[INFO 2015-10-16 18:21:14,775] END RequestId: 324cb1c5-fa9b-4f39-8ad9-01c95f7d5744
[INFO 2015-10-16 18:21:14,775] RESULT: None
[root - INFO - 2017-04-19 12:39:05,512] Event: {u'answer': 42}
[root - INFO - 2017-04-19 12:39:05,512] START RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
0
49
196
441
784
1225
[root - INFO - 2017-04-19 12:39:05,515] END RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1
[root - INFO - 2017-04-19 12:39:05,515] RESULT:
None
[root - INFO - 2017-04-19 12:39:05,515] REPORT RequestId: b918f9ae-0ca1-44af-9937-dd5f9eeedcc1 Duration: 2.27 ms

.. |Join the chat at https://gitter.im/HDE/python-lambda-local| image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/HDE/python-lambda-local?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. |wercker status| image:: https://app.wercker.com/status/04f5bc5b7de3d5c6f13eb5b871035226/s
:target: https://app.wercker.com/project/bykey/04f5bc5b7de3d5c6f13eb5b871035226
.. |PyPI version| image:: https://badge.fury.io/py/python-lambda-local.svg
:target: https://badge.fury.io/py/python-lambda-local
6 changes: 4 additions & 2 deletions lambda_local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'''
python-lambda-local: Main module
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''

from __future__ import print_function
import argparse
from main import run
import sys
from multiprocessing import Process

from .main import run


def main():
args = parse_args()
Expand Down Expand Up @@ -46,5 +47,6 @@ def parse_args():

return parser.parse_args()


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion lambda_local/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''

Expand Down
2 changes: 1 addition & 1 deletion lambda_local/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''

Expand Down
10 changes: 5 additions & 5 deletions lambda_local/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''

Expand All @@ -13,10 +13,10 @@
import timeit
from botocore.vendored.requests.packages import urllib3

import event
import context
from timeout import time_limit
from timeout import TimeoutException
from . import event
from . import context
from .timeout import time_limit
from .timeout import TimeoutException

logging.basicConfig(stream=sys.stdout,
level=logging.INFO,
Expand Down
2 changes: 1 addition & 1 deletion lambda_local/timeout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''

Expand Down
16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'''
python-lambda-local: Run lambda function in python on local machine.
Note that "python setup.py test" invokes pytest on the package. With
appropriately configured setup.cfg, this will check both xxx_test modules and
docstrings.
Copyright 2015 HDE, Inc.
Copyright 2015-2017 HDE, Inc.
Licensed under MIT.
'''
import sys
Expand All @@ -26,15 +22,19 @@ def run_tests(self):
sys.exit(pytest.main(self.test_args))


version = "0.1.3"
version = "0.1.4"

setup(name="python-lambda-local",
version=version,
description="Run lambda function in python on local machine.",
long_description=open("README.rst").read(),
classifiers=[
'Development Status :: 1 - Planning',
'Programming Language :: Python'
'Development Status :: 3 - Alpha',
'Operating System :: POSIX ',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'License :: OSI Approved :: MIT License'
],
keywords="AWS Lambda",
author="YANG Xudong",
Expand Down
Loading

0 comments on commit 9bcdd5b

Please sign in to comment.