mhart / kinesalite

An implementation of Amazon's Kinesis built on LevelDB
MIT License
808 stars 86 forks source link

Does not work with @aws-sdk/client-kinesis (v3) #118

Open alesmenzel opened 2 years ago

alesmenzel commented 2 years ago

Hi, the library does not seem to work with the v3 AWS SDK for Node.

"@aws-sdk/client-kinesis": "^3.105.0",

Here is a sample repro:

const { KinesisClient, ListStreamsCommand } = require('@aws-sdk/client-kinesis')

const main = async () => {
    const client = new KinesisClient({
        region: 'us-west-1',
        endpoint: 'http://localhost:4567',
        credentials: {
            accessKeyId: 'accessKeyId',
            secretAccessKey: 'secretAccessKey',
        },
    })
    try {
        await client.send(
            new ListStreamsCommand({
                Limit: 1,
            })
        )
    } catch (err) {
        console.log(err)
        process.exit(1)
    } finally {
        client.destroy()
    }
}

main()

and I am getting this vague error

Error [ERR_HTTP2_ERROR]: Protocol error
    at new NghttpError (node:internal/http2/util:555:5)
    at Http2Session.onSessionInternalError (node:internal/http2/core:784:26) {
  code: 'ERR_HTTP2_ERROR',
  errno: -505,
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

if I enable the SSL option for kinesalite (npx kinesalite --port=4567 --createStreaMs=5 --ssl) then I get

Error: Unexpected error: http2 request did not get a response
    at ClientHttp2Stream.<anonymous> (.../node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http2-handler.js:105:28)
    at ClientHttp2Stream.emit (node:events:390:28)
    at emitCloseNT (node:internal/streams/destroy:138:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

when I try to connect to kinesalite with aws cli then it seems to work (no SSL only)

$ aws --endpoint-url=http://localhost:4567 kinesis list-streams --region eu-west-1
{
    "StreamNames": [] // I have not created any, so this is correct
}

I believe this to be a bug in kinesalite.

garyhuntddn commented 1 year ago

Just hit the same - it appears that kinesalite supports HTTP/1.1 but doesn't support HTTP/2

garyhuntddn commented 1 year ago

If you're still interested @alesmenzel then you can do the following to force the v3 SDK to use an HTTP/1.1 connection.

...

import { NodeHttpHandler } from "@aws-sdk/node-http-handler";

...

const kinesisConfig: KinesisClientConfig = {
  ...
  requestHandler: new NodeHttpHandler()
};
const kinesisClient = new KinesisClient( kinesisConfig );
vweevers commented 1 year ago

FYI, the package @aws-sdk/node-http-handler has been deprecated and replaced with @smithy/node-http-handler. So the above workaround is now:

import { NodeHttpHandler } from "@smithy/node-http-handler";

const kinesisConfig: KinesisClientConfig = {
  ...
  requestHandler: new NodeHttpHandler()
};
const kinesisClient = new KinesisClient( kinesisConfig );