{"id":25409181,"url":"https://github.com/enter-at/python-aws-lambda-handlers","last_synced_at":"2026-06-11T20:25:46.301Z","repository":{"id":38974390,"uuid":"192556060","full_name":"enter-at/python-aws-lambda-handlers","owner":"enter-at","description":"An opinionated Python package that facilitates specifying AWS Lambda handlers including input validation, error handling and response formatting.","archived":false,"fork":false,"pushed_at":"2026-06-03T21:44:13.000Z","size":545,"stargazers_count":19,"open_issues_count":25,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-06-08T09:27:51.349Z","etag":null,"topics":["aws-lambda","http","json-schema","marshmallow","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/lambda-handlers/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enter-at.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-06-18T14:25:49.000Z","updated_at":"2024-07-23T01:43:37.000Z","dependencies_parsed_at":"2023-07-14T00:47:28.612Z","dependency_job_id":"8744bc5b-4160-4a80-919d-35ff80d7dd16","html_url":"https://github.com/enter-at/python-aws-lambda-handlers","commit_stats":null,"previous_names":["enter-at/lambda-handlers"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/enter-at/python-aws-lambda-handlers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enter-at%2Fpython-aws-lambda-handlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enter-at%2Fpython-aws-lambda-handlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enter-at%2Fpython-aws-lambda-handlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enter-at%2Fpython-aws-lambda-handlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enter-at","download_url":"https://codeload.github.com/enter-at/python-aws-lambda-handlers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enter-at%2Fpython-aws-lambda-handlers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34217312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","http","json-schema","marshmallow","python"],"created_at":"2025-02-16T08:19:54.538Z","updated_at":"2026-06-11T20:25:46.280Z","avatar_url":"https://github.com/enter-at.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n\n  ** DO NOT EDIT THIS FILE\n  **\n  ** This file was automatically generated by the `build-harness`.\n  ** 1) Make all changes to `README.yaml`\n  ** 2) Run `make init` (you only need to do this once)\n  ** 3) Run`make readme` to rebuild this file.\n  **\n\n  --\u003e\n\n[\u003cimg src=\"https://res.cloudinary.com/enter-at/image/upload/v1576145406/static/logo-svg.svg\" alt=\"enter-at\" width=\"100\"\u003e][website]\n\n# python-aws-lambda-handlers [![Build Status](https://github.com/enter-at/python-aws-lambda-handlers/workflows/Code%20checks%20and%20tests/badge.svg)](https://github.com/enter-at/python-aws-lambda-handlers/actions?query=workflow%3A%22Code+checks+and+tests%22) [![Release](https://img.shields.io/pypi/v/lambda-handlers.svg)](https://pypi.org/project/lambda-handlers/) [![Code Climate Maintainability](https://api.codeclimate.com/v1/badges/852b53c3aab82fe1ebe7/maintainability)](https://codeclimate.com/github/enter-at/python-aws-lambda-handlers/maintainability) [![Code Climate Test Coverage](https://api.codeclimate.com/v1/badges/852b53c3aab82fe1ebe7/test_coverage)](https://codeclimate.com/github/enter-at/python-aws-lambda-handlers/test_coverage)\n\n\nAn opinionated Python package that facilitates specifying AWS Lambda handlers including\ninput validation, error handling and response formatting.\n\n\n---\n\n\nIt's 100% Open Source and licensed under the [APACHE2](LICENSE).\n\n\n\n\n\n\n\n\n\n\n\n\n\n# Quickstart\n\n## Installation\n\nTo install the latest version of lambda-handlers simply run:\n\n```bash\npip install lambda-handlers\n```\n\nIf you are going to use validation, we have examples that work with\n[Marshmallow](https://pypi.org/project/marshmallow/) or\n[jsonschema](https://pypi.org/project/jsonschema/).\n\nBut you can adapt a LambdaHandler to use your favourite validation module.\nPlease share it with us or create an issue if you need any help with that.\n\nBy default the `http_handler` decorator makes sure of parsing the request body\nas JSON, and also formats the response as JSON with:\n    - an adequate statusCode,\n    - CORS headers, and\n    - the handler return value in the body.\n\n\n## Basic ApiGateway Proxy Handler\n```python\nfrom lambda_handlers.handlers import http_handler\n\n@http_handler()\ndef handler(event, context):\n    return event['body']\n```\n# Examples\n\n## HTTP handlers\n\nSkipping the CORS headers default and configuring it.\n\n```python\nfrom lambda_handlers.handlers import http_handler\nfrom lambda_handlers.response import cors\n\n@http_handler(cors=cors(origin='localhost', credentials=False))\ndef handler(event, context):\n    return {\n        'message': 'Hello World!'\n    }\n```\n\n```bash\naws lambda invoke --function-name example response.json\ncat response.json\n```\n\n```json\n{\n    \"headers\":{\n        \"Access-Control-Allow-Origin\": \"localhost\",\n        \"Content-Type\": \"application/json\"\n    },\n    \"statusCode\": 200,\n    \"body\": \"{\\\"message\\\": \\\"Hello World!\\\"}\"\n}\n```\n\n## Validation\n\nUsing jsonschema to validate a User model as input.\n\n```python\nfrom typing import Any, Dict, List, Tuple, Union\n\nimport jsonschema\n\nfrom lambda_handlers.handlers import http_handler\nfrom lambda_handlers.errors import EventValidationError\n\nclass SchemaValidator:\n    \"\"\"A payload validator that uses jsonschema schemas.\"\"\"\n\n    @classmethod\n    def validate(cls, instance, schema: Dict[str, Any]):\n        \"\"\"\n        Raise EventValidationError (if any error) from validating \n        `instance` against `schema`.\n        \"\"\"\n        validator = jsonschema.Draft7Validator(schema)\n        errors = list(validator.iter_errors(instance))\n        if errors:\n            field_errors = sorted(validator.iter_errors(instance), key=lambda error: error.path)\n            raise EventValidationError(field_errors)\n\n    @staticmethod\n    def format_errors(errors: List[Dict[str, Any]]) -\u003e List[Dict[str, Any]]:\n        \"\"\"Re-format the errors from JSONSchema.\"\"\"\n        path_errors: Dict[str, List[str]] = defaultdict(list)\n        for error in errors:\n            path_errors[error.path.pop()].append(error.message)\n        return [{path: messages} for path, messages in path_errors.items()]\n\nuser_schema: Dict[str, Any] = {\n    'type': 'object',\n    'properties': {\n        'user_id': {'type': 'number'},\n    },\n}\n\n@http_handler()\ndef handler(event, context):\n    user = event['body']\n    SchemaValidator.validate(user, user_schema)\n    return user\n```\n\n```bash\naws lambda invoke --function-name example --payload '{\"body\": {\"user_id\": 42}}' response.json\ncat response.json\n```\n\n```json\n{\n    \"headers\":{\n        \"Access-Control-Allow-Credentials\": true,\n        \"Access-Control-Allow-Origin\": \"*\",\n        \"Content-Type\": \"application/json\"\n    },\n    \"statusCode\": 200,\n    \"body\": \"{\\\"user_id\\\": 42}\"\n}\n```\n\nUsing Marshmallow to validate a User model as input body and response body.\n\n```python\nfrom typing import Any, Dict, List, Tuple, Union\n\nfrom marshmallow import Schema, fields, ValidationError\n\nfrom lambda_handlers.handlers import http_handler\nfrom lambda_handlers.errors import EventValidationError\n\nclass SchemaValidator:\n    \"\"\"A data validator that uses Marshmallow schemas.\"\"\"\n\n    @classmethod\n    def validate(cls, instance: Any, schema: Schema) -\u003e Any:\n        \"\"\"Return the data or raise EventValidationError if any error from validating `instance` against `schema`.\"\"\"\n        try:\n            return schema.load(instance)\n        except ValidationError as error:\n            raise EventValidationError(error.messages)\n\nclass UserSchema(Schema):\n    user_id = fields.Integer(required=True)\n\n@http_handler()\ndef handler(event, context):\n    user = event['body']\n    SchemaValidator.validate(user, UserSchema())\n    return user\n```\n\n```bash\naws lambda invoke --function-name example --payload '{\"body\": {\"user_id\": 42}}' response.json\ncat response.json\n```\n\n```json\n{\n    \"headers\":{\n        \"Access-Control-Allow-Credentials\": true,\n        \"Access-Control-Allow-Origin\": \"*\",\n        \"Content-Type\": \"application/json\"\n    },\n    \"statusCode\": 200,\n    \"body\": \"{\\\"user_id\\\": 42}\"\n}\n```\n\n```bash\naws lambda invoke --function-name example --payload '{\"body\": {\"user_id\": \"peter\"}}' response.json\ncat response.json\n```\n\n```json\n{\n    \"headers\":{\n        \"Access-Control-Allow-Credentials\": true,\n        \"Access-Control-Allow-Origin\": \"*\",\n        \"Content-Type\": \"application/json\"\n    },\n    \"statusCode\": 400,\n    \"body\": \"{\\\"errors\\\": {\\\"user_id\\\": [\\\"Not a valid integer.\\\"]}\"\n}\n```\n### Headers\n\n#### Cors\n\n```python\nfrom lambda_handlers.handlers import http_handler\nfrom lambda_handlers.response import cors\n\n@http_handler(cors=cors(origin='example.com', credentials=False))\ndef handler(event, context):\n    return {\n        'message': 'Hello World!'\n    }\n```\n\n```bash\naws lambda invoke --function-name example response.json\ncat response.json\n```\n\n```json\n{\n    \"headers\":{\n        \"Access-Control-Allow-Origin\": \"example.com\",\n        \"Content-Type\": \"application/json\"\n    },\n    \"statusCode\": 200,\n    \"body\": \"{\\\"message\\\": \\\"Hello World!\\\"}\"\n}\n```\n### Errors\n\n```python\nLambdaHandlerError\n```\n```python\nBadRequestError\n```\n```python\nForbiddenError\n```\n```python\nInternalServerError\n```\n```python\nNotFoundError\n```\n```python\nFormatError\n```\n```python\nValidationError\n```\n\n\n\n## Share the Love\n\nLike this project?\nPlease give it a ★ on [our GitHub](https://github.com/enter-at/python-aws-lambda-handlers)!\n\n\n## Related Projects\n\nCheck out these related projects.\n\n- [node-aws-lambda-handlers](https://github.com/enter-at/node-aws-lambda-handlers) - An opinionated Typescript package that facilitates specifying AWS Lambda handlers including\ninput validation, error handling and response formatting.\n\n\n\n\n## Help\n\n**Got a question?**\n\nFile a GitHub [issue](https://github.com/enter-at/python-aws-lambda-handlers/issues).\n\n## Contributing\n\n### Bug Reports \u0026 Feature Requests\n\nPlease use the [issue tracker](https://github.com/enter-at/python-aws-lambda-handlers/issues) to report any bugs or file feature requests.\n\n### Developing\n\nIf you are interested in being a contributor and want to get involved in developing this project, we would love to hear from you!\n\nIn general, PRs are welcome. We follow the typical \"fork-and-pull\" Git workflow.\n\n 1. **Fork** the repo on GitHub\n 2. **Clone** the project to your own machine\n 3. **Commit** changes to your own branch\n 4. **Push** your work back up to your fork\n 5. Submit a **Pull Request** so that we can review your changes\n\n**NOTE:** Be sure to merge the latest changes from \"upstream\" before making a pull request!\n\n\n\n\n\n## License\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nSee [LICENSE](LICENSE) for full details.\n\n    Licensed to the Apache Software Foundation (ASF) under one\n    or more contributor license agreements.  See the NOTICE file\n    distributed with this work for additional information\n    regarding copyright ownership.  The ASF licenses this file\n    to you under the Apache License, Version 2.0 (the\n    \"License\"); you may not use this file except in compliance\n    with the License.  You may obtain a copy of the License at\n\n      https://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing,\n    software distributed under the License is distributed on an\n    \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n    KIND, either express or implied.  See the License for the\n    specific language governing permissions and limitations\n    under the License.\n\n\n\n\n\n  [website]: https://github.com/enter-at\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenter-at%2Fpython-aws-lambda-handlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenter-at%2Fpython-aws-lambda-handlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenter-at%2Fpython-aws-lambda-handlers/lists"}