Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

CloudWatch events are not handled by Zappa #1924

Open hugoalvarado opened 5 years ago

hugoalvarado commented 5 years ago

CloudWatch events triggering lambda functions are not being handled by Zappa. The events contain a json with the following format: {'awslogs': {'data': 'Dmt.....EA'}} which fails to match any of the conditions in the LambdaHandler.handler function.

Context

When configuring CloudWatch to trigger a Lambda function deployed by Zappa, I can see Zappa receiving the event and calling LambdaHandler.handler():

START RequestId: 850...e9a Version: $LATEST
Instancing..
[DEBUG] 2019-08-30T18:02:42.685Z 850...e9a Zappa Event: {'awslogs': {'data': 'H4sIA...AAA='}}
END RequestId: 850...e9a
REPORT RequestId: 850...e9a Duration: 2.53 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 67 MB

but my configured handler function is not called.

Expected Behavior

My configured function in zappa_settings.json should be executed 🌟

Actual Behavior

My function is not executed β›ˆ

Possible Fix

Add a new if condition in the handler function to look for the awslogs key in the event object/dict and trigger the configured handler function.

Steps to Reproduce

  1. Create and deploy a lambda function with Zappa. Add a simple print statement in the handler to confirm that the function is triggered.
  2. Create a CloudWatch log subscription filter that triggers the lambda function (see here)
  3. Push data to the log that triggers the subscription filter: aws logs put-subscription-filter \ --log-group-name myLogGroup \ --filter-name demo \ --filter-pattern "" \ --destination-arn arn:aws:lambda:region:123456789123:function:helloworld
  4. The lambda function will be executed, but the handler function will not.

Your Environment

dadoeyad commented 5 years ago

I just noticed that updating via zappa removes the Cloudwatch logs trigger too.