...

Cloud Computing - AWS Lambda

Back to Course

Lesson Description


Lession - #1461 AWS Lambda Serviceless Framework


The Serverless Framework helps you develop and deploy AWS Lambda functions, along with the AWS infrastructure resources they require. It's a CLI that offers structure, automation and best practices out- of- the- box, allowing you to focus on building sophisticated, event- driven, serverless architectures, comprised of Functions and Events.

The Serverless Framework is different from other application frameworks because

It manages your code as well as your infrastructure

It supports multiple languages(Node.js, Python, Java, and more>


Here are the Framework's main concepts and how they pertain to AWS and Lambda.

Functions
The code of a serverless application is deployed and executed in AWS Lambda functions.

Each function is an independent unit of execution and deployment, like a microservice. A function is simply code, deployed in the cloud, that's most often written to perform a single job similar as

  • Saving a user to the database
  • Processing a file in a database
  • Performing a scheduled task
  • Learn more on defining functions

    Events
    Functions are triggered by events. Events come from other AWS resources, for illustration

  • An HTTP request on an API Gateway URL(e.g. for a REST API>
  • A new file uploaded in an S3 bucket(e.g. for an image upload>
  • A CloudWatch schedule(e.g. run every 5 minutes>
  • A message in an SNS topic
  • A CloudWatch alert
  • And further.

    When you configure an event on a Lambda function, Serverless Framework will automatically create the infrastructure needed for that event(e.g. an API Gateway endpoint>
    and configure your functions to listen to it.

    Resources
    Resources are AWS infrastructure components which your functions use similar as

  • A DynamoDB table(e.g. for saving users posts comments data>
  • An S3 bucket(e.g. for saving images or files>
  • An SNS topic(e.g. for sending messages asynchronously>
  • Anything that can be defined in CloudFormation is supported by the Serverless Framework
  • Serverless Framework can deploy functions and their events, but also AWS resources.

    Services
    A service is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application.

    A service is configured via aserverless.yml file where you define your functions, events and AWS resources to deploy. It looks like this

    
    Copied 
    service users 
     
     functions# Your" Functions" 
     usersCreate 
     events# The" Events" that trigger this function 
    - httpApi' POST users create' 
     usersDelete 
     events 
    - httpApi' DELETE users delete' 
     
     resources# The" Resources" your" Functions" use. Raw AWS CloudFormation goes in then. 
     service users 
     
     functions# Your" Functions" 
     usersCreate 
     events# The" Events" that trigger this function 
    - httpApi' POST users create' 
     usersDelete 
     events 
    - httpApi' DELETE users delete' 
    
     resources# The" Resources" your" Functions" use. Raw AWS CloudFormation goes in here.
     


    When deploying with the Framework via serverless deploy, everything in the configuration file is deployed at once.