Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a newer version of the aws-sdk than provided in AWS Lambda?

The latest version of the aws-sdk has functions for ComprehendMedical, which I'd like to create a lambda function for.

However, the version of the AWS-SDK is a few months outdated, and not able to use these functions yet. Wondering if there is a way to use the latest library?

Thank you!

like image 632
Stephen A. Lizcano Avatar asked Dec 14 '18 15:12

Stephen A. Lizcano


3 Answers

I recommend you create a Library bundle and create a Lambda Layer with it with the desired version of AWS-SDK in the Library bundle (including any other libraries that you want). Once you have the Lambda layer set you can assign it to your Lambda function(s). This helps with a reduced code size of your Lambda function without having the need to bundle up all the libraries you need with every single Lambda Function. Considering AWS-SDK to be a pretty large library, Lambda Layer will help you manage the size of your individual Lambda functions with purely your code in it.

The steps are simple.

  1. Create a directory named nodejs, this is going to be your project directory. The name must be nodejs.
  2. Perform npm init inside of this directory.
  3. Install all the libraries from npm using npm install --save. Note: local install is important.
  4. Once done, zip up the nodejs directory and upload it to a Lambda Layer.
  5. Use the Lambda Layer in all your Lambda functions.

Check out my article for the full details on how to set up a Lambda Layer for Node JS dependencies. I reckon that going forward, Lambda Layer should be everyone's choice of dependency management in Lambda.

NOTE: Lambda Layer was introduced recently in AWS re:Invent 2018. It is not only compatible with NodeJS, but also with pretty much any other Language (as per Amazon) like Python, Java, C#, C++ (yes!), Go, Rust etc.

like image 146
AnBisw Avatar answered Nov 15 '22 06:11

AnBisw


Yes, you simply need to bundle the latest version of the SDK in your Lambda function's deployment file, instead of relying on the version that is there.

like image 38
Mark B Avatar answered Nov 15 '22 06:11

Mark B


On Default Lambda uses these SDKs AWS SDK for JavaScript – 2.290.0 SDK for Python (Boto3) – 3-1.7.74 botocore-1.10.74

But you can install the newest SDK via npm (or whatever you are using) and then upload the whole bunch of files to lamda.

Take a look at SLS (serverless Framework) it is easy to add files you want to deploy ;)

https://serverless.com/framework/docs/providers/aws/

https://serverless.com/framework/docs/providers/aws/guide/packaging/

like image 43
Sebastian Felix Schwarz Avatar answered Nov 15 '22 06:11

Sebastian Felix Schwarz