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

ALB event doesn't reflect custom headers specified in handler.ts #1728

Open
kappa0923 opened this issue Aug 31, 2023 · 2 comments · May be fixed by #1756
Open

ALB event doesn't reflect custom headers specified in handler.ts #1728

kappa0923 opened this issue Aug 31, 2023 · 2 comments · May be fixed by #1756

Comments

@kappa0923
Copy link

Bug Report

Current Behavior

When using the ALB event in serverless.ts, specifying the response headers in handler.ts doesn't reflect in the actual response.
No error messages are displayed.

Sample Code

Here is a minimal code snippet to reproduce the issue.

  • file: serverless.ts
service: 'my-service',
frameworkVersion: '3',
plugins: ['serverless-esbuild', 'serverless-offline'],
provider: {
  name: 'aws',
  runtime: 'nodejs18.x',
  region: 'ap-northeast-1',
  stage: 'api',
  environment: {
    AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
    NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
  },
},
functions: { 
  hello: {
    handler: 'src/functions/hello/handler.main',
    events: [
      {
        alb: {
          listenerArn: 'arn:aws:elasticloadbalancing:region:account-id:listener/app/my-load-balancer-name/load-balancer-id/abcdef1234567890',
          priority: 1,
          conditions: {
            path: ['/hello'],
            method: ['GET']
          }
        }
      }
    ]
  }
}
  • file: handler.ts
return {
  statusCode: 200,
  body: csv,
  headers: {
    'Content-Type': 'text/csv',
    'Content-Disposition': 'attachment; filename="download.csv"'
  }
}
  • Actual Request and Response
$ curl --head "http://localhost:3003/api/hello"

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
cache-control: no-cache
content-length: 2664
vary: accept-encoding
Date: Thu, 31 Aug 2023 11:42:43 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Expected Behavior/Code

The expected request and response should be:

$ curl --head "http://localhost:3003/api/hello"

HTTP/1.1 200 OK
content-type: text/csv; charset=utf-8
content-disposition: attachment; filename="download.csv"
cache-control: no-cache
content-length: 2664
vary: accept-encoding
Date: Thu, 31 Aug 2023 11:42:43 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Environment

  • serverless version: 3.34.0
  • serverless-offline version: 12.0.4
  • @serverless/typescript version: 3.30.1
  • node.js version: v18.17.0
  • OS: Debian GNU/Linux 11 (bullseye) (Running on Docker/DevContainer with WSL2/Windows 10)

Possible Solution

None

Additional Context/Screenshots

None

@ly-tc
Copy link

ly-tc commented Dec 21, 2023

Getting the same issue!

@corwinm corwinm linked a pull request Feb 6, 2024 that will close this issue
@corwinm
Copy link

corwinm commented Feb 8, 2024

Hey everyone! I opened a PR to address this. I've been running it locally using patch-package but hopefully if the PR is accepted it will be fixed for everyone needing to use ALBs.

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

Successfully merging a pull request may close this issue.

3 participants