AWS Lambda: How to create a nodejs layer for axios
nodejs axios layer for AWS Lambda

AWS Lambda: How to create a nodejs layer for axios

In previous articles, we looked at how AWS Lambda and CloudWatch can be leveraged as a powerful troubleshooting tool for integrations between various SaaS products. Since some of you may not be familiar with creating a layer, I wanted to share the steps that are needed.

More in-depth information about AWS Lambda layers can be found here.

In this article, I will provide the steps to create a nodejs layer for AWS Lambda. We will use axios, a popular package that allows for outgoing web services and API calls, as an example.

The first step is to install nodejs on a host. I am using the EC2 Amazon Linux 2023 AMI.

Amazon Linux 2023 AMI

The steps to install nodejs for Amazon Linux can be found here.

After nodejs is installed, we should be able to run the following command successfully:

node --version

Now we need to execute the following commands:

1- Create a new subdirectory called nodejs: mkdir nodejs

2- Change directory to nodejs: cd nodejs

3- Use npm to install axios: npm install axios

4- Exit the subdirectory with: cd ..

5- Create the layer with zip: zip -r axios.zip nodejs/

Commands to create the axios layer
axios layer created

We can see that the axios.zip layer file has been created. It includes the node_modules subdirectory with the required dependencies for axios.

Now we just need to import the axios layer into Lambda so we can reference it using its ARN from within nodejs Lambda Functions.

Import axios layer

I hope that you found this article helpful, especially if you are not familiar with AWS Lambda layers and if you wanted to leverage the AWS Lambda Functions that we covered in previous articles.


要查看或添加评论,请登录

Michel Bluteau的更多文章

社区洞察

其他会员也浏览了