Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use axios in lambda?

Do I have to install the axios module locally and then deploy it to lambda or is there a way to do it through the inline code editor as well in the browser?

like image 680
thedreamsaver Avatar asked Jan 20 '18 13:01

thedreamsaver


People also ask

Can I use Axios in lambda function?

If you are not using any other libraries, you can directly edit your code and save it. However if you are using libraries like lodash or axios, you will not be able to install the packages directly. To do that, create function on our local machine with all the libraries and then upload it to the AWS Lambda.

Can Lambda call external API?

Like this, we can call any REST API in our Lambda Function and perform any serverless operations on the response. To know more about Lambda functions and get a hand over the complete working code, please visit our Github Repository here.


2 Answers

You can publish a simple Node.js AWS Lambda layer with axios package and then attach created layer to your lambda.

List of commands to create .zip file for layer:

mkdir nodejs
cd nodejs
npm i axios
rm -rf package-lock.json
cd ..
zip -r axios.zip nodejs

This list of commands was taken from this article https://ljmocic.medium.com/publish-simple-node-js-aws-lambda-layer-a87c00afdd83

Create Layer enter image description here Take Layer ARN enter image description here Attach Layer to Lambda enter image description here

like image 78
SAndriy Avatar answered Sep 22 '22 22:09

SAndriy


Lambda doesn't actually bundle your package dependencies for you, except the AWS package, so yes you'd need to install it locally, zip it together and upload to the Lambda console.

like image 41
oreoluwa Avatar answered Sep 20 '22 22:09

oreoluwa