lambda-dev-server


Namelambda-dev-server JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryA simple development server for AWS Lambda functions
upload_time2024-11-30 11:40:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords aws development lambda server
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # lambda-dev-server

[![PyPI - Version](https://img.shields.io/pypi/v/lambda-dev-server.svg)](https://pypi.org/project/lambda-dev-server)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/lambda-dev-server.svg)](https://pypi.org/project/lambda-dev-server)

-----

A lightweight development server for AWS Lambda, `lambda-dev-server` emulates the Lambda environment locally by creating events and contexts for any app handler. It processes requests, generates Lambda events, and returns parsed responses—ideal for development and debugging, with hot-reloading for rapid iteration. Not intended for production use. This has been tested with lambdas that use `aws-lambda-powertools` as well with lambdas that return in the shape of `{"statusCode": 200, "body": "Hello World"}`.

## Table of Contents

- [lambda-dev-server](#lambda-dev-server)
  - [Table of Contents](#table-of-contents)
  - [Installation](#installation)
  - [Usage](#usage)
  - [Debugging](#debugging)
  - [1. Traditional Development Flow (Without `lambda-dev-server`)](#1-traditional-development-flow-without-lambda-dev-server)
    - [Drawbacks:](#drawbacks)
  - [2. Invoke/Direct Handler Call Flow (Without `lambda-dev-server`)](#2-invokedirect-handler-call-flow-without-lambda-dev-server)
    - [Drawbacks:](#drawbacks-1)
  - [3. Improved Flow with `lambda-dev-server`](#3-improved-flow-with-lambda-dev-server)
    - [Benefits:](#benefits)
  - [Conclusion](#conclusion)
  - [License](#license)

## Installation

To install `lambda-dev-server`, use pip:

```sh
pip install lambda-dev-server
```

## Usage

```bash
# Given a Lambda handler named handler in app.py
lambda-dev-server app.handler
```

## Debugging

You can configure your debugger in Visual Studio Code (VSCode) with the following `launch.json` configuration:

```json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python Debugger: Module",
      "type": "debugpy",
      "request": "launch",
      "module": "lambda_dev_server",
      "args": ["app.handler"]
    }
  ]
}
```

## 1. Traditional Development Flow (Without `lambda-dev-server`)

This diagram illustrates the development flow when using `sam start-api` or manually invoking the Lambda handler. While `sam start-api` allows using tools like Postman or curl.

```mermaid
sequenceDiagram
    participant User as User
    participant API as API Gateway
    participant SAM as AWS SAM/Local API
    participant Lambda as AWS Lambda
    participant IDE as IDE/Debugger

    User->>SAM: Use `sam start-api` (Build App)
    SAM->>API: Start Local API (API Gateway)
    User->>API: Send Request (Postman or Curl)
    API->>Lambda: Forward Request to Lambda Handler
    Lambda->>Lambda: Process Event & Context
    Lambda->>API: Return Processed Response
    API->>User: Return Response to User

    Note over SAM: Requires Build Step & Template.yaml Updates
    Note over API, Lambda: No Hot Reloading, Debugger Not Attached
    Note over User: Can Use Postman or Curl with `sam start-api`
```

### Drawbacks:
- **Manual event preparation**: When calling the Lambda handler directly via `invoke`, users must manually create events.
- **Requires `sam start-api`**: Using `sam start-api` requires building the application and maintaining a `template.yaml` file.
- **No hot reloading**: Code changes require restarting the local API, making iteration slower.
- **No debugger attachment**: Debugging during development is more complex.

---

## 2. Invoke/Direct Handler Call Flow (Without `lambda-dev-server`)

This flow demonstrates the manual process involved when invoking or calling the Lambda handler directly. Users must manually construct the event before sending it to the Lambda function.

```mermaid
sequenceDiagram
    participant User as User
    participant Lambda as AWS Lambda
    participant IDE as IDE/Debugger

    User->>User: Manually Construct Event
    User->>Lambda: Invoke or Call Lambda Handler Directly
    Lambda->>Lambda: Process Event & Context (Handler Logic)
    Lambda->>User: Return Processed Response
    User->>User: View Response

    Note over User: Must Manually Create Event
    Note over Lambda: No API Gateway or Automatic Event Simulation
    Note over IDE: No Hot Reloading or Debugger Attach in this Flow
```

### Drawbacks:
- **Manual event construction**: The user has to manually create the event, which is error-prone and cumbersome.
- **No API Gateway**: The flow lacks the built-in API Gateway to handle routing and automatic event creation.
- **No hot reloading or debugger**: Users cannot easily attach a debugger or take advantage of hot reloading in this flow.

---

## 3. Improved Flow with `lambda-dev-server`

This flow illustrates the seamless experience provided by `lambda-dev-server`. With no build steps, hot reloading, and easy event simulation, development becomes faster and easier.

```mermaid
sequenceDiagram
    participant User as User
    participant Server as Lambda Dev Server
    participant Lambda as AWS Lambda Handler
    participant IDE as IDE/Debugger

    User->>Server: Run `lambda-dev-server` with Handler
    Server->>Server: Start Web Server (Uvicorn/WSGI)
    User->>Server: Send Request (Postman or Curl)
    Server->>Server: Simulate Lambda Event & Context
    Server->>Lambda: Call Lambda Handler with Event & Context
    Lambda->>Lambda: Process Event & Context (Handler Logic)
    Lambda->>Server: Return Response
    Server->>User: Return HTTP Response

    Note over Server: No Build Step Required
    Note over Server: Hot Reloading on Code Changes
    Note over IDE: Attachable Debugger
    Note over User: Use Postman or Curl to Call API
```

### Benefits:
- **No build step**: Directly run the Lambda handler through a web server, bypassing the need to build the application.
- **Hot-reloading**: Changes to the code are reflected immediately, speeding up the development process.
- **Debugger attachment**: Easily attach a debugger to the running server for troubleshooting.
- **Automatic event simulation**: The server handles event creation and Lambda context simulation, saving time.
- **Seamless interaction**: Use tools like Postman or curl to test the handler just like a regular REST API.

---

## Conclusion

`lambda-dev-server` significantly improves the AWS Lambda development experience by allowing you to:
- Avoid the need for build steps and maintaining `template.yaml`.
- Use Postman or curl just like in regular REST API development.
- Enjoy hot reloading and easy debugging for rapid iteration.


## License

`lambda-dev-server` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "lambda-dev-server",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "aws, development, lambda, server",
    "author": null,
    "author_email": "Flavio Amurrio <25621374+FlavioAmurrioCS@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/24/b8/338a0a4709d54c0483612d5f12c47739a354ff907fca73c2e34bae244b56/lambda_dev_server-0.0.3.tar.gz",
    "platform": null,
    "description": "# lambda-dev-server\n\n[![PyPI - Version](https://img.shields.io/pypi/v/lambda-dev-server.svg)](https://pypi.org/project/lambda-dev-server)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/lambda-dev-server.svg)](https://pypi.org/project/lambda-dev-server)\n\n-----\n\nA lightweight development server for AWS Lambda, `lambda-dev-server` emulates the Lambda environment locally by creating events and contexts for any app handler. It processes requests, generates Lambda events, and returns parsed responses\u2014ideal for development and debugging, with hot-reloading for rapid iteration. Not intended for production use. This has been tested with lambdas that use `aws-lambda-powertools` as well with lambdas that return in the shape of `{\"statusCode\": 200, \"body\": \"Hello World\"}`.\n\n## Table of Contents\n\n- [lambda-dev-server](#lambda-dev-server)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [Debugging](#debugging)\n  - [1. Traditional Development Flow (Without `lambda-dev-server`)](#1-traditional-development-flow-without-lambda-dev-server)\n    - [Drawbacks:](#drawbacks)\n  - [2. Invoke/Direct Handler Call Flow (Without `lambda-dev-server`)](#2-invokedirect-handler-call-flow-without-lambda-dev-server)\n    - [Drawbacks:](#drawbacks-1)\n  - [3. Improved Flow with `lambda-dev-server`](#3-improved-flow-with-lambda-dev-server)\n    - [Benefits:](#benefits)\n  - [Conclusion](#conclusion)\n  - [License](#license)\n\n## Installation\n\nTo install `lambda-dev-server`, use pip:\n\n```sh\npip install lambda-dev-server\n```\n\n## Usage\n\n```bash\n# Given a Lambda handler named handler in app.py\nlambda-dev-server app.handler\n```\n\n## Debugging\n\nYou can configure your debugger in Visual Studio Code (VSCode) with the following `launch.json` configuration:\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"name\": \"Python Debugger: Module\",\n      \"type\": \"debugpy\",\n      \"request\": \"launch\",\n      \"module\": \"lambda_dev_server\",\n      \"args\": [\"app.handler\"]\n    }\n  ]\n}\n```\n\n## 1. Traditional Development Flow (Without `lambda-dev-server`)\n\nThis diagram illustrates the development flow when using `sam start-api` or manually invoking the Lambda handler. While `sam start-api` allows using tools like Postman or curl.\n\n```mermaid\nsequenceDiagram\n    participant User as User\n    participant API as API Gateway\n    participant SAM as AWS SAM/Local API\n    participant Lambda as AWS Lambda\n    participant IDE as IDE/Debugger\n\n    User->>SAM: Use `sam start-api` (Build App)\n    SAM->>API: Start Local API (API Gateway)\n    User->>API: Send Request (Postman or Curl)\n    API->>Lambda: Forward Request to Lambda Handler\n    Lambda->>Lambda: Process Event & Context\n    Lambda->>API: Return Processed Response\n    API->>User: Return Response to User\n\n    Note over SAM: Requires Build Step & Template.yaml Updates\n    Note over API, Lambda: No Hot Reloading, Debugger Not Attached\n    Note over User: Can Use Postman or Curl with `sam start-api`\n```\n\n### Drawbacks:\n- **Manual event preparation**: When calling the Lambda handler directly via `invoke`, users must manually create events.\n- **Requires `sam start-api`**: Using `sam start-api` requires building the application and maintaining a `template.yaml` file.\n- **No hot reloading**: Code changes require restarting the local API, making iteration slower.\n- **No debugger attachment**: Debugging during development is more complex.\n\n---\n\n## 2. Invoke/Direct Handler Call Flow (Without `lambda-dev-server`)\n\nThis flow demonstrates the manual process involved when invoking or calling the Lambda handler directly. Users must manually construct the event before sending it to the Lambda function.\n\n```mermaid\nsequenceDiagram\n    participant User as User\n    participant Lambda as AWS Lambda\n    participant IDE as IDE/Debugger\n\n    User->>User: Manually Construct Event\n    User->>Lambda: Invoke or Call Lambda Handler Directly\n    Lambda->>Lambda: Process Event & Context (Handler Logic)\n    Lambda->>User: Return Processed Response\n    User->>User: View Response\n\n    Note over User: Must Manually Create Event\n    Note over Lambda: No API Gateway or Automatic Event Simulation\n    Note over IDE: No Hot Reloading or Debugger Attach in this Flow\n```\n\n### Drawbacks:\n- **Manual event construction**: The user has to manually create the event, which is error-prone and cumbersome.\n- **No API Gateway**: The flow lacks the built-in API Gateway to handle routing and automatic event creation.\n- **No hot reloading or debugger**: Users cannot easily attach a debugger or take advantage of hot reloading in this flow.\n\n---\n\n## 3. Improved Flow with `lambda-dev-server`\n\nThis flow illustrates the seamless experience provided by `lambda-dev-server`. With no build steps, hot reloading, and easy event simulation, development becomes faster and easier.\n\n```mermaid\nsequenceDiagram\n    participant User as User\n    participant Server as Lambda Dev Server\n    participant Lambda as AWS Lambda Handler\n    participant IDE as IDE/Debugger\n\n    User->>Server: Run `lambda-dev-server` with Handler\n    Server->>Server: Start Web Server (Uvicorn/WSGI)\n    User->>Server: Send Request (Postman or Curl)\n    Server->>Server: Simulate Lambda Event & Context\n    Server->>Lambda: Call Lambda Handler with Event & Context\n    Lambda->>Lambda: Process Event & Context (Handler Logic)\n    Lambda->>Server: Return Response\n    Server->>User: Return HTTP Response\n\n    Note over Server: No Build Step Required\n    Note over Server: Hot Reloading on Code Changes\n    Note over IDE: Attachable Debugger\n    Note over User: Use Postman or Curl to Call API\n```\n\n### Benefits:\n- **No build step**: Directly run the Lambda handler through a web server, bypassing the need to build the application.\n- **Hot-reloading**: Changes to the code are reflected immediately, speeding up the development process.\n- **Debugger attachment**: Easily attach a debugger to the running server for troubleshooting.\n- **Automatic event simulation**: The server handles event creation and Lambda context simulation, saving time.\n- **Seamless interaction**: Use tools like Postman or curl to test the handler just like a regular REST API.\n\n---\n\n## Conclusion\n\n`lambda-dev-server` significantly improves the AWS Lambda development experience by allowing you to:\n- Avoid the need for build steps and maintaining `template.yaml`.\n- Use Postman or curl just like in regular REST API development.\n- Enjoy hot reloading and easy debugging for rapid iteration.\n\n\n## License\n\n`lambda-dev-server` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple development server for AWS Lambda functions",
    "version": "0.0.3",
    "project_urls": {
        "Documentation": "https://github.com/FlavioAmurrioCS/lambda-dev-server#readme",
        "Issues": "https://github.com/FlavioAmurrioCS/lambda-dev-server/issues",
        "Source": "https://github.com/FlavioAmurrioCS/lambda-dev-server"
    },
    "split_keywords": [
        "aws",
        " development",
        " lambda",
        " server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd6f8527b8e65e6eacbb368f782210a05b8b193a6c37d701c178cf1cbe13bce2",
                "md5": "3f351953eb1f6a46b0580af6125d06a9",
                "sha256": "b05c533c6309d72322f3c229f383eca8c10dd4fb73dd79ee7566c3cc7ba45bfe"
            },
            "downloads": -1,
            "filename": "lambda_dev_server-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f351953eb1f6a46b0580af6125d06a9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10302,
            "upload_time": "2024-11-30T11:40:32",
            "upload_time_iso_8601": "2024-11-30T11:40:32.052638Z",
            "url": "https://files.pythonhosted.org/packages/cd/6f/8527b8e65e6eacbb368f782210a05b8b193a6c37d701c178cf1cbe13bce2/lambda_dev_server-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "24b8338a0a4709d54c0483612d5f12c47739a354ff907fca73c2e34bae244b56",
                "md5": "af6d230a003255328fe108457ff1941f",
                "sha256": "9792b944e419ededa8ff060e82bc0d66669d19b577710250d1950688f6ec110a"
            },
            "downloads": -1,
            "filename": "lambda_dev_server-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "af6d230a003255328fe108457ff1941f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11538,
            "upload_time": "2024-11-30T11:40:50",
            "upload_time_iso_8601": "2024-11-30T11:40:50.997994Z",
            "url": "https://files.pythonhosted.org/packages/24/b8/338a0a4709d54c0483612d5f12c47739a354ff907fca73c2e34bae244b56/lambda_dev_server-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-30 11:40:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "FlavioAmurrioCS",
    "github_project": "lambda-dev-server#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "lambda-dev-server"
}
        
Elapsed time: 0.38158s