Skip to main content

No project description provided

Project description

py-lambda-simulator

py-lambda-simulator is a Python library for running aws-lambda functions locally.

Installation

Use the package manager pip to install py-lambda-simulator.

pip install py-lambda-simulator

Usage

import asyncio
import json
from asyncio import run

from py_lambda_simulator.lambda_simulator import AwsSimulator
from py_lambda_simulator.sqs_lambda_simulator import SqsLambdaSimulator, SqsEvent, LambdaSqsFunc


async def example(simulator, aws_simulator):
    queue = aws_simulator.create_sqs_queue("queue-name")

    def sqs_handler(event: SqsEvent, context):
        print(event["Records"][0]["body"])

    simulator.add_func(LambdaSqsFunc(name="test-sqs-lambda", queue_name="queue-name", handler_func=sqs_handler))

    async def send_msg():
        while True:
            aws_simulator.get_sqs_client().send_message(
                QueueUrl=queue["queue_url"], MessageBody=json.dumps({"test": 123})
            )
            await asyncio.sleep(1)

    await asyncio.gather(simulator.start(), send_msg())


if __name__ == '__main__':
    _simulator = SqsLambdaSimulator()
    _aws_simulator = AwsSimulator()
    run(example(_simulator, _aws_simulator))

For more examples see the tests.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-lambda-simulator-0.1.6.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_lambda_simulator-0.1.6-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file py-lambda-simulator-0.1.6.tar.gz.

File metadata

  • Download URL: py-lambda-simulator-0.1.6.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.11.0-40-generic

File hashes

Hashes for py-lambda-simulator-0.1.6.tar.gz
Algorithm Hash digest
SHA256 43d5bf7a97444eff852398ff2f50426e1ff524fcecabf5b485915c15090128a1
MD5 8bf2297508c8eeb605a1d528876b5120
BLAKE2b-256 050570be25cadb2a38d5996de9afdb608ea4e9816686b66cf432cc66474b5286

See more details on using hashes here.

File details

Details for the file py_lambda_simulator-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: py_lambda_simulator-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.11.0-40-generic

File hashes

Hashes for py_lambda_simulator-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b86a0cb4794318da2ecfb2a58ecd9882a3e39fec67008f8684c0309d78248409
MD5 fd2968d9f9c0b50d6f78f8cc6b51e36a
BLAKE2b-256 eed7f6e7cf59df4130cd579db9ffa8498da06593851d3098deb182bc5883e10b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page