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

ws-response: Invalid URL format gave to ApiGatewayManagementApiClient #1218

Closed
nbusser opened this issue Jun 18, 2024 · 4 comments
Closed

ws-response: Invalid URL format gave to ApiGatewayManagementApiClient #1218

nbusser opened this issue Jun 18, 2024 · 4 comments
Labels

Comments

@nbusser
Copy link

nbusser commented Jun 18, 2024

Describe the bug
When uysing ws-response and giving no awsClientOptions, a default endpoint option is given to ApiGatewayManagementApiClient.

Regarding code, the URL is created from the api endpoint and domain. However, the protocol is left unspecified, which leads to:

{
    "errorType": "TypeError",
    "errorMessage": "Invalid URL",
    "code": "ERR_INVALID_URL",
    "input": abcdefg.execute-api.eu-central-1.amazonaws.com/dev",
    "stack": [
        "TypeError [ERR_INVALID_URL]: Invalid URL",
        "    at new NodeError (node:internal/errors:405:5)",
        "    at new URL (node:internal/url:676:13)",
        "    at parseUrl (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/url-parser/dist-cjs/index.js:29:21)",
        "    at toEndpointV1 (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:112:41)",
        "    at customEndpointProvider (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:232:65)"
    ]
}

Using the following options works:

.use(
    wsResponseMiddleware({
      awsClientOptions: {
        endpoint:
          'https://abcdefg.execute-api.eu-central-1.amazonaws.com/dev',
      },
    }),
  )

Environment (please complete the following information):

  • Node.js: 20
  • Middy: 4.7.0
  • AWS SDK 3
@nbusser nbusser added the bug label Jun 18, 2024
@nbusser
Copy link
Author

nbusser commented Jun 18, 2024

If this issue is fixed, would it be possible to also fix it in middy 4.x?

Since we are using serverless-typescript, which only supports CJS, we cannot actually use ESM...

@willfarrell
Copy link
Member

Thanks for reporting! I'll should have a fix out shortly.

Sorry, no plans to ship any bug or feature updates to v4.x. I would imagine the maintainers for serverless-typescript would be open to an update to esm as the cold start improvements when running lambda are notable.

@nbusser
Copy link
Author

nbusser commented Jun 18, 2024

It makes sense. I just created a fixed local version of the middleware at the moment.

Also, shouldn't the Data property being JSON.stringify, or is it responsibility of the lambda?

@willfarrell
Copy link
Member

Responsibility of the lambda, as Data can be non-json.

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

No branches or pull requests

2 participants