Reputation: 5210
I'd like to run a function via both HTTP and cron, but not seeing any documentation that let's me determine if it was an http request or cron request (explicitly):
events:
- http:
path: /foo
method: ANY
cors:
origin: '*'
- schedule: rate(5 minute)
Is there a property in event
or context
that would allow me to detect what triggered the function?
Upvotes: 2
Views: 533
Reputation: 2954
You can always pass an input to your schedule event and use that to determine that's a schedule event
events:
- http:
path: /foo
method: ANY
cors:
origin: '*'
- schedule:
rate: rate(5 minute)
input:
isSchedule: true
There's more examples here: https://serverless.com/framework/docs/providers/aws/events/schedule/
EDIT:
Forgot about this
{
"version": "0",
"id": "53dc4d37-cffa-4f76-80c9-8b7d4a4d2eaa",
"detail-type": "Scheduled Event",
"source": "aws.events",
"account": "123456789012",
"time": "2015-10-08T16:53:06Z",
"region": "us-east-1",
"resources": [
"arn:aws:events:us-east-1:123456789012:rule/my-scheduled-rule"
],
"detail": {}
}
you can also check detail-type
field
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html
Upvotes: 1