I am running some code in AWS Lambda that dynamically creates SageMaker models. I am locking Sagemaker's API version like so:
const sagemaker = new AWS.SageMaker({apiVersion: '2017-07-24'});
And here's the code to create the model:
await sagemaker.createModel({
ExecutionRoleArn: 'xxxxxx',
ModelName: sageMakerConfigId,
Containers: [{
Image: ecrUrl
}]
}).promise()
This code runs just fine locally with aws-sdk
on 2.418.0
.
However, when this code is deployed to Lambda, it doesn't work due to some validation errors upon creating the model:
- MissingRequiredParameter: Missing required key 'PrimaryContainer' in params
- UnexpectedParameter: Unexpected key 'Containers' found in params
Is anyone aware of existing bugs in the aws-sdk
for NodeJS using the SDK provided by AWS in the Lambda context? I believe the SDK available inside AWS Lambda is more up-to-date than 2.418.0
but apparently there are compatibility issues.
As you've noticed the 'embedded' lambda version of the aws-sdk lags behind. It's actually on
2.290.0
(you can see the full details on the environment here: https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html)You can see here: https://github.com/aws/aws-sdk-js/blame/master/clients/sagemaker.d.ts that it is not until
2.366.0
that the params for this method includedContainers
and did not requirePrimaryContainer
.As you've noted, the workaround is to deploy your lambda with the
aws-sdk
version that you're using. This is sometimes noted as a best practice, as it pins theaws-sdk
on the functionality you've built and tested against.I have managed to fix it by removing
aws-sdk
fromdevDependencies
in mypackage.json
and moved it todependencies
instead, so Lambda will be forced to use it.Still, this is clearly a bug to me.