Event Driven Architecture with Lambda

The advantage of using lambda is there’s no queue system (celery) that causes no blocking.  You use events to spawn lambdas for each event that comes in.  Configure/use this with the zappa project.

To resize a thumbnail on a user uploading a picture, you run a function based on a save to s3.

events:
  - function: users.util.process_avatar
    event_source:
     arn: arn:aws:s3:::your_event_name

Don’t get stuck in an infinite loop!  Use two buckets (processed/raw), or set path of new object so that it doesn’t trigger your event.

If your function takes a long time to run, then you don’t want to use the event driven architecture because it’ll time out.  Use zappa.async import task.  API endpoint calls the task wrapped function, which then starts a new async server that runs the longer code and returns.

 

Leave a comment