Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a support for a default AWS event handler #2115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,18 @@ def your_recurring_function(event, context):

You can find more [example event sources here](http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html).

You can also respond to events dynamically using the `default_event_handler` setting, which can be useful for handling events from unknown sources or sources configured at run time:

```javascript
{
"production": {
...,
"default_event_handler": "your_module.your_handler_function",
...
}
}
```

## Asynchronous Task Execution

Zappa also now offers the ability to seamlessly execute functions asynchronously in a completely separate AWS Lambda instance!
Expand Down
3 changes: 3 additions & 0 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,9 @@ def create_package(self, output=None):
event_mapping[arn] = function
settings_s = settings_s + "AWS_EVENT_MAPPING={0!s}\n".format(event_mapping)

default_event_handler = self.stage_config.get('default_event_handler')
settings_s = settings_s + "AWS_DEFAULT_EVENT_HANDLER={0!r}\n".format(default_event_handler)

# Map Lext bot events
bot_events = self.stage_config.get('bot_events', [])
bot_events_mapping = {}
Expand Down
2 changes: 1 addition & 1 deletion zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def get_function_for_aws_event(self, record):
arn = record['s3']['bucket']['arn']

if arn:
return self.settings.AWS_EVENT_MAPPING.get(arn)
return self.settings.AWS_EVENT_MAPPING.get(arn, self.settings.AWS_DEFAULT_EVENT_HANDLER)

return None

Expand Down