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

Only top method is used in alb event with multiple methods #1771

Open
apokryfos opened this issue Mar 19, 2024 · 0 comments
Open

Only top method is used in alb event with multiple methods #1771

apokryfos opened this issue Mar 19, 2024 · 0 comments

Comments

@apokryfos
Copy link

Bug Report

The ALB event documentation allows specifying multiple methods. However if I try to run my configuration using serverless-offline, only the top method is used.

Current Behavior

Sample Code

  • file: serverless.yml
service: my-service

plugins:
  - serverless-webpack
  - serverless-offline
custom:
  serverless-offline:
    httpPort: 3000
    host: 0.0.0.0 

provider:
  name: aws
  runtime: nodejs18.x

functions:
  myFunc:
    handler: src/alb.myFunc
    events:
      - alb:
          listenerArn: <some value, probably not important>
          priority: <some other value, probably not important>
          conditions:
            host: <host>
            path: /api/*
            method:
              - POST
              - GET

Expected behavior/code

When I run sls offline I expect there to be two listeners on the /{stage}/api path but instead I only get one i.e.

What I currently see:

   ┌──────────────────────────────────────────────────────────────────────────────┐
   │                                                                              │
   │   POST | http://0.0.0.0:3003/dev/api/{0}                                     │
   │   POST | http://0.0.0.0:3003/2015-03-31/functions/myFunc/invocations         │
   │                                                                              │
   └──────────────────────────────────────────────────────────────────────────────┘

What I was expecting to see:

   ┌──────────────────────────────────────────────────────────────────────────────┐
   │                                                                              │
   │   POST | http://0.0.0.0:3003/dev/api/{0}                                     │
   │   GET  | http://0.0.0.0:3003/dev/api/{0}                                     │
   │   POST | http://0.0.0.0:3003/2015-03-31/functions/myFunc/invocations         │
   │                                                                              │
   └──────────────────────────────────────────────────────────────────────────────┘

Environment

  • serverless version: [e.g. v3.28.1]
  • serverless-offline version: [e.g. v13.3.3]
  • node.js version: [e.g. v18.19.1]
  • OS: Ubuntu 22.04.4

Possible Solution

The issue seems to be at https://github.com/dherault/serverless-offline/blob/master/src/events/alb/HttpServer.js#L297 where the method is selected as

method = albEvent.conditions.method[0].toUpperCase()

a possible solution would be to not select the first method but keep the methods as an array then iterate through each to create an hapiHandler and route

I don't currently have time to make a PR but if no one else can I can come back to this when time permits.

apokryfos pushed a commit to apokryfos/serverless-offline that referenced this issue Mar 28, 2024
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

1 participant