Pass custom data to HTTP event

Hey guys,

I want to pass custom data for each http event in serverless.yml. Is that somehow possible? Unfortunately I couldn’t find anything so far.

Here is an example:

test:
    handler: handlers/index.handle
    events:
      - http:
          path: test
          method: get
          cors: true
          foo: bar # <--- Something like that

Thanks a lot, really appreciate ya help!

have you found an answer? please update if you do, or someone else please answer this.
i am having the exact same question for my project. any help is deeply appreciated.

Unfortunately not and as far as it looks like there is no possibility except writing an own Event handler (copy of API Gateway handler) with custom parameters and validator. I wanted to pass an option to set a dynamic function that should be executed. Doing it now by checking event.resource and event.httpMethod in an index handler with many if else statements. Not the perfect way for sure but a workaround that works for me.

Are you trying to pass something from the caller or just something statically defined in your serverless.yml?

If it’s just a static value, you could pass it in as an environment variable instead of a request parameter.
editing your example:
test:

    handler: handlers/index.handle
    events:
      - http:
          path: test
          method: get
          cors: true
    environment:
      FOO: bar

The if using Node.js, reference it in your Lambda with:

process.env.FOO

Thank, but I know that I can pass environment variables per handler but I want to pass it to the http event and not the entire function.