- Newest
- Most votes
- Most comments
Check the event object if it contains the "detail-type" field or not. if it does, it is from EventBrdige. If it does not, it is a manual invocation.
I think the question is this: Is the date parameter you are trying to parse added based on some custom logic of yours, or just the date of the invocation?
If it is just the datetime of invocation then you could read it out of the event parameters passed by EventBridge.
If the datetime is based on a custom logic, then what you could do is have the source of the event, pass that custom data into a custom event, which an EventBridge rule would then pass to Lambda. This custom data would be in the "detail" section of the EventBridge custom event.
One thing to also consider, Lambda Powertools has some nice utilities that make it easy to parse Event sources, like EventBridge, and will handle all the logging for you to make it easy to inspect what was passed, which generally makes it easier to develop and troubleshoot, imo.
Thanks for the suggestions
when it's called automatically from the EventBridge, it doesn''t have a parameter.
EventBridge automatically generates event
for Lambda invocations, and its structure is described in this page. You cannot specify event
for invocations triggered by EventBridge.
What is the correct way of checking if it's called using the above (--data ''2023-09-03") or the way it is called from the EventBridge?
No, there is no way to check the caller principal within your Lambda function (though you can retrieve the user identity for Cognito users from context
input argument).
You might check the structure of the event
, but this won't work because you can pass the same structure as other callers (e.g., EventBridge, SNS) with manual invokes to bypass the check.
The only way to tell the caller of a specific function invocation is to use CloudTrail logging to capture data events for Lambda execution and analyze the detail (e.g., userIdentity
) of the invocation by its request ID. This way might not be what you want.
Relevant content
- Accepted Answerasked a year ago
- asked 5 months ago
- AWS OFFICIALUpdated a year ago
Is the "date" being passed today's date? Is there a reason why you cannot programmatically get the date inside the function being called instead of passing a date to it?