Home > Net >  lambda_handler for cron expression
lambda_handler for cron expression

Time:08-14

Im running a Python Lambda using cron from event bridge every minute.

what should I pass to my function lambda_handler(event, context):

as event ? since there'e actually not real event, its just a cron job.

CodePudding user response:

Why are you passing anything to the handler? Are you asking purely for testing purposes?

Like you said, the event isn't important in this scenario, so your code can safely ignore the event, which means you don't need to pass anything when you are testing either.

When your Lambda function is deployed, AWS will be the one calling the lambda_handler function. That is the entry point to your code. You never call lambda_handler directly via your code.

CodePudding user response:

since there'e actually not real event, its just a cron job.

There will be an event associated with the EventBridge request: it will be a Scheduled Event event.

Here's an example from the documentation:

{
  "version": "0",
  "account": "123456789012",
  "region": "us-east-2",
  "detail": {},
  "detail-type": "Scheduled Event",
  "source": "aws.events",
  "time": "2019-03-01T01:23:45Z",
  "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c",
  "resources": [
    "arn:aws:events:us-east-2:123456789012:rule/my-schedule"
  ]
}

You'll never need to specify neither the event nor the context arguments.

  • Related