Skip to main content

AWS Lambda event handler manager

Project description

Domovoi is an extension to AWS Labs Chalice to handle AWS Lambda event sources other than HTTP requests through API Gateway. Domovoi lets you easily configure and deploy a Lambda function to run on a schedule or in response to an SNS push notification:

import json, boto3, domovoi

app = domovoi.Domovoi()

@app.scheduled_function("cron(0 18 ? * MON-FRI *)")
def foo(event, context):
    context.log("foo invoked at 06:00pm (UTC) every Mon-Fri")
    return dict(result=True)

@app.scheduled_function("rate(1 minute)")
def bar(event, context):
    context.log("bar invoked once a minute")
    boto3.resource("sns").create_topic(Name="bartender").publish(Message=json.dumps({"beer": 1}))
    return dict(result="Work work work")

@app.sns_topic_subscriber("bartender")
def tend(event, context):
    message = json.loads(event["Records"][0]["Sns"]["Message"])
    context.log(dict(beer="Quadrupel", quantity=message["beer"]))

@app.cloudwatch_event_handler(source=["aws.ecs"])
def monitor_ecs_events(event, context):
    message = json.loads(event["Records"][0]["Sns"]["Message"])
    context.log("Got an event from ECS: {}".format(message))

@app.s3_event_handler(bucket="myS3bucket", events=["s3:ObjectCreated:*"], prefix="foo", suffix=".bar")
def monitor_s3(event, context):
    message = json.loads(event["Records"][0]["Sns"]["Message"])
    context.log("Got an event from S3: {}".format(message))

Installation

pip install domovoi

Usage

First-time setup:

chalice new-project

Replace the Chalice app entry point (in app.py) with the Domovoi app entry point as above, then deploy the event handlers:

domovoi deploy

To stage files into the deployment package, use a domovoilib directory in your project where you would use chalicelib in Chalice. For example, my_project/domovoilib/rds_cert.pem becomes /var/task/domovoilib/rds_cert.pem with your function executing in /var/task/app.py with /var/task as the working directory. See the Chalice docs for more information on how to set up Chalice configuration.

Supported event types

See http://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html for an overview of event sources that can be used to trigger Lambda functions. Domovoi supports the following event sources:

TODO:

  • CloudWatch Logs filter subscriptions

  • DynamoDB events

  • SES (email) events

License

Licensed under the terms of the Apache License, Version 2.0.

https://travis-ci.org/kislyuk/domovoi.png https://codecov.io/github/kislyuk/domovoi/coverage.svg?branch=master https://img.shields.io/pypi/v/domovoi.svg https://img.shields.io/pypi/l/domovoi.svg https://readthedocs.org/projects/domovoi/badge/?version=latest

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

domovoi-1.0.8.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

domovoi-1.0.8-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file domovoi-1.0.8.tar.gz.

File metadata

  • Download URL: domovoi-1.0.8.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for domovoi-1.0.8.tar.gz
Algorithm Hash digest
SHA256 c3b2d09eb1c40d26701ddfd7ee464dd455b18bac854be0b63bcea987edeccc29
MD5 477797efbda68a09349dfa54aafec7af
BLAKE2b-256 0566838a161893c4a4773da83d8c674d21fae7b727a9e3921fe0ebac9645c19f

See more details on using hashes here.

File details

Details for the file domovoi-1.0.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for domovoi-1.0.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0c587c51362768fb60a0bb17f57abad598309cc235cd8d26762752572d890ac8
MD5 e3d9bd8c7c7712687fcc7fdeeb705f42
BLAKE2b-256 38b045d5326a1e52354b1ff7c5410d80f71ce4c086c1240fa6f15836fc790864

See more details on using hashes here.

Supported by

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