AWS Lambda Layers - Node Js

Image
by Revathi Ganapuram  Adding Layers in AWS Lambda Overview :   A Lambda layer is an archive containing additional code, such as libraries, dependencies, or even custom runtimes. The layer later can be used by adding in Layers option in AWS Lambda.     In this post, we will learn how to create and add layers for node js functions in AWS Lambda. Firstly, we will create a sample code of printing current data and time like below For this we have created  a folder named AWSLAYERS , in that we have added initialized 'npm init'. Next, for printing date and time we need moment module, let's install it. npm install moment --save.   After successful installation of `moment` a node module package will be created inside folder and also package.json file. Now here comes the actual part, create a folder names 'nodejs' and move nodemodules, package.json (package-lock.json also , if present) inside nodejs folder. After moving the folder structure should be as below. ...

AWS Lambda Function - Node Js

by Revathi Ganapuram

 Creating NodeJs Function in AWS Lambda


    Hello guys, today we will create a Lambda function using NodeJs as runtime directly in AWS Console.

Introduction to AWS :

    AWS Lambda is a server less computing service provided by Amazon to reduce the configuration of servers, OS, Scalability, etc. AWS Lambda is capable of executing code on AWS Cloud.

It runs in response to events on different AWS resources, which triggers AWS Lambda functions.


Let’s Start :

    Before starting in order to write a function in AWS , we need a AWS account. The process of creating a AWS Account is simple and requires only few minutes.

  • After successful creation and login in AWS Console , click on 'Lambda' on services or simply search 'Lambda' in search bar.
  • Click on create function.
    • Select 'Author from Scratch', provide any function name and select 'NodeJs 14.x ' as runtime from dropdown and click on 'Create Function'.
    • For example, here I'm creating a function naming as 'demo'.
    

  • On successful creation, you will forwarded to below screen.
            


  • As we can see on left side under code, we have project folder with index.js file created.
  • On double click of index file it will open up in editor where you can modify or update your code and test.
  • Here following are the few things we have to consider.
    • First, 'exports.handler' is the main thing the lambda function checks for when we test the code. It is the main function.
    • Secondly, In 'Runtime settings' we have Handler updated already by our main file name followed by function which is index.handler. if you like to rename the function make sure you update the Handler too.
    • Lastly, whenever we do changes in code , make sure to deploy those changes by clicking on Deploy before testing.
  • Finally we can test the code by creating a sample test event and click on test, the output must be as shown.


Thank You.


Comments

Popular posts from this blog

AWS Lambda Layers - Node Js