Create a Demo Layer with `axios` Using PowerShell

Learn how to create an AWS Lambda layer with `axios` using PowerShell in a few simple steps.
Module 1: Create a Demo Layer with axios
Using PowerShell #
-
Open PowerShell.
-
Navigate to your working directory or create a new one:
New-Item -ItemType Directory -Path my-lambda-layer Set-Location -Path my-lambda-layer
-
Initialize a new Node.js project:
npm init -y
-
Install
axios
:npm install axios
-
Create the necessary directory structure for the layer:
New-Item -ItemType Directory -Path layer/nodejs -Force
-
Move the
node_modules
andpackage.json
to the layer directory:Move-Item -Path node_modules -Destination layer/nodejs Move-Item -Path package.json -Destination layer/nodejs
Your directory structure should now look like this:
my-lambda-layer/
└── layer
└── nodejs
├── node_modules
│ └── axios
└── package.json
- Zip the
layer/nodejs
directory:Compress-Archive -Path layer/nodejs -DestinationPath my-lambda-layer.zip
You now have a zipped file, my-lambda-layer.zip
, which contains the axios
library and can be uploaded as a Lambda layer in AWS.
To upload and use the layer in AWS Lambda:
- Go to the AWS Lambda Console.
- Navigate to "Layers" and click "Create layer".
- Provide a name for the layer, upload the
my-lambda-layer.zip
file, and specify the compatible runtimes (e.g., Node.js 14.x, Node.js 16.x). - Click "Create".
After creating the layer, you can add it to your Lambda function:
- Go to your Lambda function in the AWS Console.
- In the "Layers" section, click "Add a layer".
- Choose "Custom layers" and select the layer you just created.
- Click "Add".
Now, your Lambda function will have access to the axios
library, and you can use it in your Lambda handler code.