AWS Lambda : Serverless Framework

beginner level

Aws Lambda is serverless compute service that runs code and manages resources for you.

Why?

  • Totally Event Driven

  • Support Multiple Languages

  • Fully Scalable

  • Use Pay-as-you-go Model

UseCases:

  • Log Analysis

  • Working with External Services

  • Operate serverless websites

  • Automated backups and daily Tasks

  • CleanUp Backend

  • Document Conversation


Prerequisite

  • IAM user with Administrator access

  • install nodejs in local

Action Time

let's open your code editor, I am using vs code. open a terminal and install the serverless package,

npm install -g serverless

Now, let's configure IAM user credentials to use with serverless.

serverless config credentials --provider aws --key xxxx --secret xxx --profile serverless-admin

you will get output similar to this,

Now hit one by one command as below,

SLS

select the first option and follow the prompt and finish it.

let's verify in the console,

The directory structure of Function,

Lets you modify lambda function code and you need to deploy new changes,

make sure you are hitting command inside of my demo folder,

sls deploy

we saw that it took 86 seconds to deploy changes because it deploy everything again.

let us suppose you have modified the lambda function and want to deploy updated changes only.

sls deploy function -f hello

Invoke Lambda

sls invoke -f hello

check logs,

sls invoke -f hello --log


CleanUp

Need to remove the below all,

  • lambda function

  • dependency function

  • cloud watch logs

  • everything that is created using a serverless framework

sls remove