-
Notifications
You must be signed in to change notification settings - Fork 584
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
TypeError: Illegal invocation while assuming role #6690
Comments
Hey @neerajtk13 , Thanks for this feedback! This typically happens due to incorrect binding of the STS client. I can't reproduce this issue. I can share my working reproduction code with you. const { STSClient, AssumeRoleCommand } = require("@aws-sdk/client-sts");
let credentials = null;
let expiration = null;
let client = null;
const refreshBuffer = 300000; // 5 minutes
const RoleArn = "arn:aws:iam::XXX:role/s3-role";
const RoleSessionName = "session1";
const DurationSeconds = 900;
const initializeClient = () => {
if (!client) {
client = new STSClient({
region: "us-west-2",
});
}
};
const assumeRole = async (roleArn, sessionName, sessionDuration) => {
try {
const command = new AssumeRoleCommand({
RoleArn: roleArn,
RoleSessionName: sessionName,
DurationSeconds: sessionDuration,
});
console.log("Sending AssumeRoleCommand with parameters:", {
RoleArn: roleArn,
RoleSessionName: sessionName,
DurationSeconds: sessionDuration,
});
const response = await client.send(command);
console.log("Assumed role successfully:", response);
credentials = {
accessKeyId: response.Credentials.AccessKeyId,
secretAccessKey: response.Credentials.SecretAccessKey,
expiration: response.Credentials.Expiration,
sessionToken: response.Credentials.SessionToken,
};
expiration = new Date(response.Credentials.Expiration).getTime();
return credentials;
} catch (err) {
console.error("Error assuming role:", err);
throw new Error("Failed to assume role");
}
};
const getCredentials = async () => {
initializeClient();
const currentTime = Date.now();
if (credentials && expiration - currentTime > refreshBuffer) {
console.log("Returning cached credentials.");
return credentials;
}
console.log("Credentials expired or not available; refetching...");
return await assumeRole(RoleArn, RoleSessionName, DurationSeconds);
};
module.exports = getCredentials; When I export the module like this - Could you please check if you can update the export module part to - module.exports = getCredentials; |
Do you by chance have this line in your esbuild config file: platform: "node", Was just facing this issue in an electron app and the solution was to remove that line. |
I don't have this line in the config. I just check the esbuild doc
Since I don't have this line, it sets to default value, which is Please LMK if you have other questions! Thanks! |
im using electron-builder i dont have esbuild-config file or this platform: "node" line of code anywhere. |
my code is working on first time role creation and when that session expires upon rehitting the assumerole function im getting this illegal invocation error |
@neerajtk13 |
Checkboxes for prior research
Describe the bug
Regression Issue
SDK version number
"@aws-sdk/client-sts": "^3.696.0"
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
electron js : 21.1.0, Node js: 18.12.0
Reproduction Steps
im running this inside my electron app.
Observed Behavior
the code is failing at const response = await client.send(command);
it is saying TypeError: Illegal invocation while assuming role. it used to work fine till last week .
Expected Behavior
Should return credentials response
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: