SageMaker NodeJS's SDK is not locking the API

2019-08-15 13:48发布

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.

2条回答
再贱就再见
2楼-- · 2019-08-15 14:18

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 included Containers and did not require PrimaryContainer.

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 the aws-sdk on the functionality you've built and tested against.

查看更多
家丑人穷心不美
3楼-- · 2019-08-15 14:33

I have managed to fix it by removing aws-sdk from devDependencies in my package.json and moved it to dependencies instead, so Lambda will be forced to use it.

"dependencies": {
    "aws-sdk": "^2.418.0"
  }

Still, this is clearly a bug to me.

查看更多
登录 后发表回答