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.7.tar.gz (5.4 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.7-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-lambda-simulator-0.1.7.tar.gz
  • Upload date:
  • Size: 5.4 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.7.tar.gz
Algorithm Hash digest
SHA256 c02f22e6ba1bc5a5eb969ce24327e2c8041982167537226f73d68d48994417d4
MD5 d19edad554f63154edc4d5509429c1f4
BLAKE2b-256 61b7746d75f67e1cea51efa86fc60a9cca917e8c221a229b24186910c9f89805

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_lambda_simulator-0.1.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d520d073db9bea282f5263035f060cb5a3a8b9f1d9a01c92e4bcd92d4637a1f0
MD5 1584c7b14057c98c77db7df27c07b0a0
BLAKE2b-256 b9b78134dbb335caef5396db8deae6cff94e9241ac6308d2563584bfcc26957b

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