How can I use axios in lambda?

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.


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