client-lambda UpdateAliasCommand throws an InternalError
Checkboxes for prior research
- [x] I've gone through Developer Guide and API reference
- [x] I've checked AWS Forums and StackOverflow.
- [x] I've searched for previous similar issues and didn't find any solution.
Describe the bug
When attempting to update a lambda alias with weighted routing config, the SDK throws an InternalError:
// Publish version 1 of the lambda
// Create an initial alias pointing to version 1
await lambdaClient.send(
new CreateAliasCommand({
FunctionName: "my-test-function",
Name: "active",
FunctionVersion: "1",
}),
);
// Publish version 2 of the lambda
// Attempt to update the alias to point to version 2 and 1
await lambdaClient.send(
new UpdateAliasCommand({
FunctionName: "my-test-function",
FunctionVersion: "2",
Name: "active",
RoutingConfig: {
AdditionalVersionWeights: {
1: 0.95,
},
},
}),
);
The lambdaClient.send at the end throws:
exception while calling lambda.UpdateAlias: LambdaProvider._create_routing_config_model() missing 1 required positional argument: 'function_version'
InternalError: exception while calling lambda.UpdateAlias: LambdaProvider._create_routing_config_model() missing 1 required positional argument: 'function_version'
at throwDefaultError (/Users/--user--/sample-service/node_modules/@smithy/smithy-client/dist-cjs/index.js:388:20)
at /Users/--user--/sample-service/node_modules/@smithy/smithy-client/dist-cjs/index.js:397:5
at de_CommandError (/Users/--user--/sample-service/node_modules/@aws-sdk/client-lambda/dist-cjs/index.js:4079:14)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at /Users/--user--/sample-service/node_modules/@smithy/middleware-serde/dist-cjs/index.js:36:20
at /Users/--user--/sample-service/node_modules/@smithy/core/dist-cjs/index.js:193:18
at /Users/--user--/sample-service/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
at /Users/--user--/sample-service/node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
at Object.<anonymous> (/Users/--user--/sample-service/tests/alias.test.js:150:23)
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v24.4.1
Reproduction Steps
Start a localstack container and configure lambdaClient, then deploy a function, create an alias, update the function, and attempt to update the alias:
// Publish version 1 of the lambda
await lambdaClient.send(
new CreateFunctionCommand({
FunctionName: "my-test-function",
Runtime: "nodejs22.x",
Role: "arn:aws:iam::000000000000:role/lambda-role",
Handler: "index.handler",
Code: {
ZipFile: readFileSync("tests/function.zip"),
},
Timeout: 30,
MemorySize: 128,
Publish: true,
}),
);
// Wait for the lambda to be active
// Create an initial alias pointing to version 1
await lambdaClient.send(
new CreateAliasCommand({
FunctionName: "my-test-function",
Name: "active",
FunctionVersion: "1",
}),
);
// Publish version 2 of the lambda
await lambdaClient.send(
new UpdateFunctionCodeCommand({
FunctionName: "my-test-function",
ZipFile: readFileSync("tests/function-updated.zip"),
Publish: true,
}),
);
// Wait for the update to be successful
// Attempt to update the alias to point to version 2 and 1
await lambdaClient.send(
new UpdateAliasCommand({
FunctionName: "my-test-function",
FunctionVersion: "2",
Name: "active",
RoutingConfig: {
AdditionalVersionWeights: {
1: 0.95,
},
},
}),
);
Observed Behavior
The UpdateAliasCommand fails with an InternalError:
exception while calling lambda.UpdateAlias: LambdaProvider._create_routing_config_model() missing 1 required positional argument: 'function_version'
InternalError: exception while calling lambda.UpdateAlias: LambdaProvider._create_routing_config_model() missing 1 required positional argument: 'function_version'
at throwDefaultError (/Users/--user--/sample-service/node_modules/@smithy/smithy-client/dist-cjs/index.js:388:20)
at /Users/--user--/sample-service/node_modules/@smithy/smithy-client/dist-cjs/index.js:397:5
at de_CommandError (/Users/--user--/sample-service/node_modules/@aws-sdk/client-lambda/dist-cjs/index.js:4079:14)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at /Users/--user--/sample-service/node_modules/@smithy/middleware-serde/dist-cjs/index.js:36:20
at /Users/--user--/sample-service/node_modules/@smithy/core/dist-cjs/index.js:193:18
at /Users/--user--/sample-service/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
at /Users/--user--/sample-service/node_modules/@aws-sdk/client-lambda/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
at Object.<anonymous> (/Users/--user--/sample-service/tests/alias.test.js:150:23)
Expected Behavior
The lambda alias is updated with the weighted routing config.
Possible Solution
No response
Additional Information/Context
No response
Hi @athielke - thanks for reaching out.
According to service API model, FunctionVersion refers to the version the alias invokes. Looking at your code, you created alias with version 1, update function code to publish but how are you able to verify if the FunctionVersion of the alias you created was updated to 2?
Also does updateAlias fail with both versions?
Hi @aBurmeseDev
My sample code doesn't show it, but I was using the returned function version from the UpdateFunctionCodeCommand. The only command that fails is the last UpdateAliasCommand:
// Attempt to update the alias to point to version 2 and 1
await lambdaClient.send(
new UpdateAliasCommand({
FunctionName: "my-test-function",
FunctionVersion: "2",
Name: "active",
RoutingConfig: {
AdditionalVersionWeights: {
1: 0.95,
},
},
}),
);
However, if you remove the RoutingConfig section, that last update alias works:
// Attempt to update the alias to point to version 2 and 1
await lambdaClient.send(
new UpdateAliasCommand({
FunctionName: "my-test-function",
FunctionVersion: "2",
Name: "active",
}),
);
Could you verify the RoutingConfig of that alias? You may use GetAlias to check its RoutingConfig.
This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.
Calling GetAlias returns the version of the alias I created without any routing config:
const getAlias = await lambdaClient.send(
new GetAliasCommand({
FunctionName: "my-test-function",
Name: "active",
}),
);
console.log(getAlias);
returns
{
'$metadata': {
httpStatusCode: 200,
requestId: '93d8bb49-75b0-4e6c-abfc-0f776269fe31',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
AliasArn: 'arn:aws:lambda:us-east-1:000000000000:function:my-test-function:active',
Description: '',
FunctionVersion: '1',
Name: 'active',
RevisionId: '2add1dc3-42ef-48b5-b54b-d5b4cbe8bdcf'
}