Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stageVariables per http event #188

Closed
linus-amg opened this issue Jan 18, 2017 · 4 comments
Closed

stageVariables per http event #188

linus-amg opened this issue Jan 18, 2017 · 4 comments

Comments

@linus-amg
Copy link

linus-amg commented Jan 18, 2017

hi, awesome plugin

i want to define stageVariables inside every of my http events,

i did so like this:

functions:
  status:
    handler: handler.status
    events:
      - http:
          method: GET
          path: /
          integration: lambda
          cors: true
          stageVariables:
            handler: test

but stageVariables is an empty object in my event argument:

https://www.dropbox.com/s/1j0po5mrjyk61l0/Screenshot%202017-01-18%2012.24.57.png?dl=0

am i missing something?

@dherault
Copy link
Owner

Hi @elgubenis, thanks for reporting this issue.

Did you solve it, and if yes, how ?

@linus-amg
Copy link
Author

i solved it by modifying a fork of your plugin:

linus-amg@1a58a3b

but it has nothing to do with serverless, so i did not try to make a PR, its a very custom solution for the project im working on (its great though!)

thank you so much for your plugin, it saves so much time.

the final .yml syntax is

functions:
  status:
    handler: status
    events:
       - http:
           method: GET
           path: status
           handler: getStatus
      - http:
           method: POST
           path: status
           handler: setStatus

like that i can have this handler in aws lambda:

const restWrap = (obj) => {
  return (event, context, cb) => {
    const method = obj[event.handler]; // <-- thanks to the mod
    return method(event, context, cb);
  };
};

module.exports.status = restWrap({
  getStatus: (event, context, cb) => ...,
  setStatus: (event, context, cb) => ...,
});

i did all this to group rest endpoints by resource, so i dont need to have 1 aws lambda function per endpoint, so in the end i have 1 aws lambda function per function, but with many different endpoints accessing the resource

@dherault
Copy link
Owner

Thanks for explaining that

@linus-amg
Copy link
Author

linus-amg commented Jan 19, 2017

for anybody interested, i also created a serverless-plugin which deploys this behavior to the Api Gateway Method, you can find it here: https://github.com/elgubenis/serverless-event-handler sorry for the lack of documentation, yet, also the way im adding the handler to the requestTemplate is pretty ugly, i recommend not using until further...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants