Skip to main content
# python-lambda-local

Run lambda function on local machine

## Prepare development environment

Please use a newly created virtualenv for python2.7.

## Installation

Within virtualenv, run the following command.

``` bash
$ cd $PROJECT_ROOT
$ pip install ./
```

This will install the package with name `python-lambda-local` in the virtualenv.
Now you can use the command `python-lambda-local` to run your AWS Lambda function written in Python on your own machine.

## Usage

Run `python-lambda-local -h` to see the help.

```
usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]
[-t TIMEOUT]
FILE EVENT

Run AWS Lambda function written in Python on local machine.

positional arguments:
FILE Lambda function file name
EVENT Event data file name.

optional arguments:
-h, --help show this help message and exit
-l LIBRARY_PATH, --library LIBRARY_PATH
Path of 3rd party libraries.
-f HANDLER_FUNCTION, --function HANDLER_FUNCTION
Lambda function handler name. Default: "handler".
-t TIMEOUT, --timeout TIMEOUT
Seconds until lambda function timeout. Default: 3
```

### Prepare development directory

#### Project directory structure

Suppose your project directory is like this:

```
├── event.json
├── lib
│   ├── 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
└── 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.

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

``` python
from rx import Observable


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

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

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

#### Run the lambda function

Within the project root directory, you can run the lambda function with the following command

```
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
```

Metadata

Release files for python-lambda-local 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-lambda-local 0.1
File Size Uploaded
python-lambda-local-0.1.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-lambda-local 0.1
File Interpreter ABI Platform
python_lambda_local-0.1-py2-none-any.whl Python 2 none any Details

Total release size: 13.7 kB

Release files / python-lambda-local-0.1.tar.gz

Download URL python-lambda-local-0.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5687cf7273d5d2f091531cbb3a979b44288772c8e37750b13e4d487f26b3fcd4
BLAKE2b-256 checksum
How to use checksums
fbedee87083b38759457005ee34341a5cee6fd498b06e1f6d573fba10fc2114b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_lambda_local-0.1-py2-none-any.whl

Download URL python_lambda_local-0.1-py2-none-any.whl
Size 8.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
c9177cc9ae07d08f69da4a372495d0ab357fc9f855dfd55c4edbc5782cb788f2
BLAKE2b-256 checksum
How to use checksums
ec9febd1d7d974a9a7d94ef6ddac3e6a95ec7f76087513ce7512fd735cdef199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.12

3 release files

0.1.11

3 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

3 release files

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

2 release files

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page