CS/클라우드컴퓨팅

10 Serverless I

호프 2023. 12. 5. 17:36

Serverless

Microservices

Microservices

  • An architecture that is loosely coupled
  • An architectural and organizational approach to software development
    • Software is composed of small independent services
    • Communicate over well-defined APIs
    • Owned by small, self-contained teams

Microservicce: SW System을 작은 독립적인 서비스들로 나누는 아키텍처 스타일로 여러 모듈로 구성된 작은 서비스들이 독립적으로 배포, 확장, 관리될 수 있도록 설계한다.

 

Tightly vs Loosely Coupled

  • Tightly Coupled: monolithic architecture
  • Loosely Coupled: microservices architecture
    • Microservices is better approach: more durable, reliable, and manageable

Downside of Monoliths

  • All processes are tightly coupled and run as a single service.
  • Adding or improving a monolithic application's features becomes more complex as the code base grows.
  • Dependent and tightly coupled processes increase the impact of a single process failure.

Benefits of Microservices

  • Use public APIs: Microservices communicate over APIs -> Hide your data and document of your APIs
  • Use the right tool for the job: built for explicit functionality
  • Secure your services: provide security at every step
  • Be a good citizen: 각 microservice가 책임을 가지고 서로 협력해야 함
  • Company transformation: shift requires transformation in the organization and communication mechanism btw teams
  • Automate everything

 

Serverless

Serverless

  • With serverless computing, you can build and run applications and services without thinking about servers.
    • Developers can focus on their code product not worrying about managing and operating servers or runtimes
  • Serverless technologies can complement traditional application models.
    • You can build nearly any type of application or backend service

Microservices and Serverless Architecture

  • Microservice: method of building your architecture
  • Serverless: service that's used to build your architcture

마이크로서비스는 소프트웨어 아키텍처의 한 방식이며, 서버리스 아키텍처는 그 방법 중 하나를 실현하기 위해 사용되는 특정한 서비스나 플랫폼

 

Benefits of Serverless

  • No server management
  • Pay-for-value services: you never pay for over-provisioning
  • Continuous scaling: most serverless services can be configured to scale automataically
  • High availability

 

Event-Driven Architecture

 

Event-Driven Architecture

  • Uses events to initiate actions and communication btw decoupled services.
  • When event occurs, the information is published for other services to consume it.
  • In event-driven architecture, events are the primary mechanism for sharing information across services

Benefits of Event-Driven Architecture

  • Scale and fail independently
    • by decoupling your services, they are only aware of the event router, not each other
    • if one service has a failure, the rest will keep running
  • Audit with ease
    • event router acts as a centralized location to audit
  • Develop with agility
    • event router will automatically filter and push events to customers
  • Cut costs
    • on-demand -> not paying for continuous polling to check for an event

AWS Lambda

AWS Lambda

AWS Lambda

  • serverless, event-driven compute service
  • can run code
  • Challenge: you need coding experience and expertise with:
    • Linux OS commands and concepts
    • Familiarity with AWS IAM
    • Cloud concepts and IP networking
    • Distributed computing concepts

Design Best Practices

  • Separate business logic
  • Modulara functions
  • Treat functions as stateless
  • Only include what you need

 

AWS Lambda Function

Three Ways to Build an AWS Lambda Function

  1. Author from scratch
    • Hello World examples include just enough code for your choosen language to get started
  2. Use a blueprint
    • bluprints are language-specific samples that include function code and settings for a runtime and trigger combination
  3. Container image
    • you can select container image to deploy for your function when creating a function
    • containers are a method of OS virtualization taht allow you to run an application and its dependencies in resource-isolated processes

Function Basic Information

  • Basic components of an AWS Lambda function include the function name, runtime, and permissions.

Handler Method

  • Lambda function handler is the method in your function code that processes events
  • Handler Method takes two objects
    • Event object: all of the data and metadata Lambda function needs to drive its logic
    • Context object: allow your function code to interact with the Lambda execution environment

 

Configuring Options

Configuring Memory and Timeout

  • Lambda allocates CPU powers in proportion to the amount of memory configured
    • Memory is the amount of memory available to your Lambda function at runtime
  • Lambda runs your code for a set amount of time before timing out
    • Timeout is the maximum amount of time in seconds that a Lambda function can run

Configuring Concurrency and Scaling

  • Concurrency: number of requests your function can handle at the same time
    • for each concurrent request, Lambda provisions a separate instance of your execution environment
    • Reserved Concurrency: guarantees the maximum number of cconcurrent instances
    • Provisioned Concurrency: initializes a requested number of execution environments instances so that they are prepared to respond imediately to your function's invocations
  • Lambda automatically handles scaling the number of execution environments

Choosing a Trigger

  • You can configure other AWS services to trigger your function each time a specified event occurs

Destination

  • Destination can send records of asynchronous invocations to other services
  • Can configure separete destinations for failed events and successed events
  • Can configure destinations on a function, a version, or an alias
  • With destinations, you can address errors and successes without needing to write more code

Types of Monitoring Graphs

  • Invocations: number of times that your function code run
  • Duration: amount of time that your function code spends processing an event
  • Errors: number of invocations that result in a error
  • Throttles: number of times that a process failed because of concurrency limits
  • IteratorAge: the age of the last record in the event
  • Concurrent executions: number of function instances that are processing events

 

Amazon CloudWatch Lambda Insights

Amazon CloudWatch Lambda Insights

  • monitoring and troubleshooting solution for serverless applications running on Lambda
  • Lambda Insights collect, aggregate, summarize system-level metrics and diagonostic information such as cold starts and Lambda worker shutdowns

Lambda Insights Dashboard

  • Multi-function
    • aggregates the runtime metrics for the Lambda functions in the concurrent AWS account and Region
    • identify over and under utilized Lambda functions
  • Single-function
    • shows the available runtime metrics for a single Lambda function
    • troubleshoot invidiual requests