I'm getting a Cannot read properties of undefined (reading 'sso_session') error when trying use this library to connect to an MSK Serverless cluster from an EC2 instance. I've verified I can connect to the instance from the same EC2 instance using a java client based on these instructions, so it seems like it may be an issue with this library?
I confess I don't understand this library, so forgive me if the issue lies elsewhere. I appreciate any help you can provide. Please let me know if you need additional details.
Error
TypeError: Cannot read properties of undefined (reading 'sso_session')
at /home/ec2-user/sandbox/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/fromSSO.js:15:21
at async coalesceProvider (/home/ec2-user/sandbox/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:14:24)
at async AuthenticationPayloadCreator.provider (/home/ec2-user/sandbox/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:33:24)
at async AuthenticationPayloadCreator.create (/home/ec2-user/sandbox/node_modules/@jm18457/kafkajs-msk-iam-authentication-mechanism/src/AuthenticationPayloadCreator.js:91:43)
at async Object.authenticate (/home/ec2-user/sandbox/node_modules/@jm18457/kafkajs-msk-iam-authentication-mechanism/src/AwsIamAuthenticator.js:34:25)
at async SASLAuthenticator.authenticate (/home/ec2-user/sandbox/node_modules/kafkajs/src/broker/saslAuthenticator/index.js:73:5)
at async /home/ec2-user/sandbox/node_modules/kafkajs/src/network/connection.js:139:9
at async Connection.authenticate (/home/ec2-user/sandbox/node_modules/kafkajs/src/network/connection.js:315:5)
at async Broker.connect (/home/ec2-user/sandbox/node_modules/kafkajs/src/broker/index.js:111:7)
at async /home/ec2-user/sandbox/node_modules/kafkajs/src/cluster/brokerPool.js:93:9
Debug Logs
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.060Z","logger":"kafkajs","message":"[Connection] Connecting","broker":"<REDACTED>","clientId":"my-app","ssl":true,"sasl":true}
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.123Z","logger":"kafkajs","message":"[Connection] Request ApiVersions(key: 18, version: 2)","broker":"<REDACTED>","clientId":"my-app","correlationId":0,"expectResponse":true,"size":20}
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.127Z","logger":"kafkajs","message":"[Connection] Response ApiVersions(key: 18, version: 2)","broker":"<REDACTED>","clientId":"my-app","correlationId":0,"size":350,"data":{"errorCode":0,"apiVersions":[{"apiKey":0,"minVersion":0,"maxVersion":9},{"apiKey":1,"minVersion":0,"maxVersion":12},{"apiKey":2,"minVersion":0,"maxVersion":6},{"apiKey":3,"minVersion":0,"maxVersion":11},{"apiKey":4,"minVersion":0,"maxVersion":5},{"apiKey":5,"minVersion":0,"maxVersion":3},{"apiKey":6,"minVersion":0,"maxVersion":7},{"apiKey":7,"minVersion":0,"maxVersion":3},{"apiKey":8,"minVersion":0,"maxVersion":8},{"apiKey":9,"minVersion":0,"maxVersion":7},{"apiKey":10,"minVersion":0,"maxVersion":3},{"apiKey":11,"minVersion":0,"maxVersion":7},{"apiKey":12,"minVersion":0,"maxVersion":4},{"apiKey":13,"minVersion":0,"maxVersion":4},{"apiKey":14,"minVersion":0,"maxVersion":5},{"apiKey":15,"minVersion":0,"maxVersion":5},{"apiKey":16,"minVersion":0,"maxVersion":4},{"apiKey":17,"minVersion":0,"maxVersion":1},{"apiKey":18,"minVersion":0,"maxVersion":3},{"apiKey":19,"minVersion":0,"maxVersion":7},{"apiKey":20,"minVersion":0,"maxVersion":6},{"apiKey":21,"minVersion":0,"maxVersion":2},{"apiKey":22,"minVersion":0,"maxVersion":4},{"apiKey":23,"minVersion":0,"maxVersion":4},{"apiKey":24,"minVersion":0,"maxVersion":3},{"apiKey":25,"minVersion":0,"maxVersion":3},{"apiKey":26,"minVersion":0,"maxVersion":3},{"apiKey":27,"minVersion":0,"maxVersion":1},{"apiKey":28,"minVersion":0,"maxVersion":3},{"apiKey":29,"minVersion":0,"maxVersion":2},{"apiKey":30,"minVersion":0,"maxVersion":2},{"apiKey":31,"minVersion":0,"maxVersion":2},{"apiKey":32,"minVersion":0,"maxVersion":4},{"apiKey":33,"minVersion":0,"maxVersion":2},{"apiKey":34,"minVersion":0,"maxVersion":2},{"apiKey":35,"minVersion":0,"maxVersion":2},{"apiKey":36,"minVersion":0,"maxVersion":2},{"apiKey":37,"minVersion":0,"maxVersion":3},{"apiKey":38,"minVersion":0,"maxVersion":2},{"apiKey":39,"minVersion":0,"maxVersion":2},{"apiKey":40,"minVersion":0,"maxVersion":2},{"apiKey":41,"minVersion":0,"maxVersion":2},{"apiKey":42,"minVersion":0,"maxVersion":2},{"apiKey":43,"minVersion":0,"maxVersion":2},{"apiKey":44,"minVersion":0,"maxVersion":1},{"apiKey":45,"minVersion":0,"maxVersion":0},{"apiKey":46,"minVersion":0,"maxVersion":0},{"apiKey":47,"minVersion":0,"maxVersion":0},{"apiKey":48,"minVersion":0,"maxVersion":1},{"apiKey":49,"minVersion":0,"maxVersion":1},{"apiKey":50,"minVersion":0,"maxVersion":0},{"apiKey":51,"minVersion":0,"maxVersion":0},{"apiKey":56,"minVersion":0,"maxVersion":0},{"apiKey":57,"minVersion":0,"maxVersion":0},{"apiKey":60,"minVersion":0,"maxVersion":0},{"apiKey":61,"minVersion":0,"maxVersion":0}],"throttleTime":0,"clientSideThrottleTime":0}}
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.128Z","logger":"kafkajs","message":"[Broker] Verified support for SaslAuthenticate","broker":"<REDACTED>","supportAuthenticationProtocol":true}
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.131Z","logger":"kafkajs","message":"[Connection] Request SaslHandshake(key: 17, version: 1)","broker":"<REDACTED>","clientId":"my-app","correlationId":1,"expectResponse":true,"size":33}
{"level":"DEBUG","timestamp":"2022-11-14T19:43:01.133Z","logger":"kafkajs","message":"[Connection] Response SaslHandshake(key: 17, version: 1)","broker":"<REDACTED>","clientId":"my-app","correlationId":1,"size":23,"data":{"errorCode":0,"enabledMechanisms":["AWS_MSK_IAM"]}}
{"level":"ERROR","timestamp":"2022-11-14T19:43:01.137Z","logger":"kafkajs","message":"[SaslAuthenticator-AWS_MSK_IAM] Cannot read properties of undefined (reading 'sso_session')","broker":"<REDACTED>"}
{"level":"ERROR","timestamp":"2022-11-14T19:43:01.137Z","logger":"kafkajs","message":"[BrokerPool] Cannot read properties of undefined (reading 'sso_session')","retryCount":0,"retryTime":285}
TypeError: Cannot read properties of undefined (reading 'sso_session')
at /home/ec2-user/sandbox/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/fromSSO.js:15:21
at async coalesceProvider (/home/ec2-user/sandbox/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:14:24)
at async AuthenticationPayloadCreator.provider (/home/ec2-user/sandbox/node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:33:24)
at async AuthenticationPayloadCreator.create (/home/ec2-user/sandbox/node_modules/@jm18457/kafkajs-msk-iam-authentication-mechanism/src/AuthenticationPayloadCreator.js:91:43)
at async Object.authenticate (/home/ec2-user/sandbox/node_modules/@jm18457/kafkajs-msk-iam-authentication-mechanism/src/AwsIamAuthenticator.js:34:25)
at async SASLAuthenticator.authenticate (/home/ec2-user/sandbox/node_modules/kafkajs/src/broker/saslAuthenticator/index.js:73:5)
at async /home/ec2-user/sandbox/node_modules/kafkajs/src/network/connection.js:139:9
at async Connection.authenticate (/home/ec2-user/sandbox/node_modules/kafkajs/src/network/connection.js:315:5)
at async Broker.connect (/home/ec2-user/sandbox/node_modules/kafkajs/src/broker/index.js:111:7)
at async /home/ec2-user/sandbox/node_modules/kafkajs/src/cluster/brokerPool.js:93:9
Code
const { Kafka, logLevel } = require('kafkajs')
const {
awsIamAuthenticator,
Type
} = require('@jm18457/kafkajs-msk-iam-authentication-mechanism')
async function main() {
const kafka = new Kafka({
clientId: 'my-app',
brokers: ['<REDACTED>'],
logLevel: logLevel.DEBUG,
ssl: true,
sasl: {
mechanism: Type,
authenticationProvider: awsIamAuthenticator('us-east-1')
}
});
const admin = kafka.admin()
// remember to connect and disconnect when you are done
await admin.connect()
const topics = await admin.listTopics()
console.log('TOPICS', topics);
await admin.disconnect()
console.log('Ending program')
}
main()
.then(() => {
console.log('DONE');
})
.catch((e) => {
console.error(e);
});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I'm getting a
Cannot read properties of undefined (reading 'sso_session')
error when trying use this library to connect to an MSK Serverless cluster from an EC2 instance. I've verified I can connect to the instance from the same EC2 instance using a java client based on these instructions, so it seems like it may be an issue with this library?I confess I don't understand this library, so forgive me if the issue lies elsewhere. I appreciate any help you can provide. Please let me know if you need additional details.
Error
Debug Logs
Code