Cloud Computing and Serverless - robbiehume/CS-Notes GitHub Wiki

Links


Serverless Architecture

  • Serverless doesn't actually mean there's no server, it means that you as the developer don't have to care about the server behind the scenes
    • As the developer, you don't have to care about writing code for a server, creating a server, maintaining a server, or deploying a server
    • It allows you to focus on code instead of web server infrastructure

JAMstack (JavaScript, APIs, and Markup)

  • Goal is to host things that become super fast and easy to serve to a user and easy for the developer to host
  • You use serverless functions for the host to just take care of things

Severless Functions

  • Only pay for the amount of time used or requests received by your functions

Pros and Cons of Severless:

  • No server maintenance
  • Low cost and easy to scale
    • Serverless functions spin up when you need them and spin don't when you don't, so you're only paying for what you use
  • Con: typically no access to a file system, so can't keep a state in memory

AWS Lambda Functions:

  • Event-driven approach; code functions only run when a trigger occurs
    • Ex: if a file is uploaded to an S3 storage bucket, take a certain action

AWS API Gateway:

  • Allows you to create a RESTful API for AWS services (Lambda, EC2, etc.)
    • Ex: can setup an API that runs a Lambda function when you make a certain HTTP request (GET, POST, etc.)

AWS Lambdas

  • Lambdas automatically run our code without requiring us to provision or manage any servers
  • Lambdas also automatically scale our applications by running code in response to each trigger. Our code runs in parallel and processes each trigger individually, scaling precisely with the size of the workload
  • They can take in data and take action on / with it
  • You only pay for the amount of time that your code is running
  • Lambdas can execute code for any type of application
  • Lambdas can handle multiple requests by provisioning containers to run them in
  • Lambdas are region-specific

EC2 vs Lambda

  • Lambdas have low maintenance, but lower flexibility
  • EC2s have high flexibility, but higher maintenance
  • Lambdas abstract load balancing, auto scaling, sercurity, OS management, etc. that come with EC2

Lambda code / function

  • Need a handler function that will be be executed upon invocation
  • The handler will receive an Event and Context object
    • Event object: relevant data sent during Lambda function invocation
    • Context object: methods available to interact with runtime information (request ID, log group, etc.)

Lambda runtime API and layers

  • Runtime API enables developers to use Lambda with any programming language
  • Layers allow you to easily share code; upload a layer once and be able to reference it within any function
    • Layers also provide separation of responsibilities

Lambda execution models

  • Synchronous (push): a request is made and a response is returned
    • Ex: an API call is made to a specific endpoint
  • Asynchronous (event): takes actions that don't need to happen in a specific order; the client isn't expecting anything in return
    • Ex: do something when an object is uploaded to an S3 bucket
  • Poll-based: constantly look for messages in a stream, and then pass them into a Lambda function

AWS Step Functions

  • Allows you to limit orchestration and having multiple Lambda functions call each other