amazon-web-servicesaws-lambdaschedulerinvoke

How to "Invoke" AWS Lambda function from EventBridge Scheduler with path?


I'm trying to configure AWS EventBridge Scheduler to invoke Lambda with path but couldn't.

I can invoke Lambda function (Nuxt3 application), but the invoked path is "/".

I want to invoke it with path like "/api/v1/hoge".

According to the AWS user guide of https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html "Input" seems to be the place to set the path information, I guess.

I also checked Lambda Invoke API description below https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax but it's not JSON format.

Can I specify path information into the "Input" of EventBridge Scheduler target?

    LambdaScheduler:
      Type: AWS::Scheduler::Schedule
      Properties:
        FlexibleTimeWindow:
          MaximumWindowInMinutes: 5
          Mode: FLEXIBLE
        Name: lambda-schedule
        ScheduleExpression: cron(0/15 * * * ? *)
        State: ENABLED
        Target:
          Arn: !GetAtt HogeLambdaFunction.Arn
          Input: |-
            << WHAT SHOULD I WRITE HERE TO SPECIFY PATH TO BE INVOKED? >>
          RoleArn: !GetAtt SchedulerRole.Arn
          DeadLetterConfig:
            Arn: !GetAtt DeadLetterQueue.Arn

Solution

  • AWS Lambda receives inputs from other services. Usually (or IMHO the most prominent use case) AWS Lambda is invoked from an API Gateway or a function url via HTTPs. To do this the calling service transforms the receiving call into a JSON representing it and then the JSON is ingested by the lambda. (So HTTPs -> JSON and then Lambda parses the JSON to get information about the initiating HTTPs call).

    The basic execution pattern of lambda is to be called with JSON and not via HTTP, if that makes sense. You can get a glimpse of this when trying to create a test call for Lambda.

    AWS EventBridge does have a custom event notification format (there is a template for it in the test console for AWS Lambda), which can be used. Only the HTTP-JSON does have a context of a "path", but the event notification JSON generated from EventBridge does not.

    There are these solutions:

    For the last point you can use a static json text or an input transformer and this JSON format.