skip to Main Content

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?

  • CloudFormation sample:
    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

2

Answers


  1. Chosen as BEST ANSWER

    Thank you very much Augunrik!

    That was the one I was looking for!

    I chose the 3rd one from your suggestions. I updated my CloudFormation code like below and it worked! (The 'rawPath' was necessary item, anyway.)

        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: |-
                {
                  "version": "2.0",
                  "rawPath": "/api/v1/hoge",
                  "requestContext": {
                    "http": {
                      "method": "GET",
                      "path": "/api/v1/hope",
                      "protocol": "HTTP/1.1"
                    }
                  }
                }
              RoleArn: !GetAtt SchedulerRole.Arn
              DeadLetterConfig:
                Arn: !GetAtt DeadLetterQueue.Arn
    

    This was my first question in stack overflow :-) I could drill down the knowledge about AWS. Thank you again, Augunrik!


  2. 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:

    • Create a customized lambda that parses the event bridge json and executes the actions (or calls your already existing lambda)
    • Your lambda uses the event bridge json instead of the http-json
    • Use a custom event bridge notification json.

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search