# AWS Certified Solutions Architect - Associate (Serverless) ###### tags: `AWS` ### Lambda AWS lambda is a compute service where you can upload your code and create a Lambda function. - Data centres - Hardware - Assembly Code/Protocols - High Level Languages - Operating Systems - Application Layer/AWS APIs - AWS Lambda #### Following ways - Event-driven - Run your code in response to HTTP requests using Amazon API Gateway ![](https://i.imgur.com/bAQdb3C.png) ![](https://i.imgur.com/MArZiOi.png) #### Traditional vs Serverless Architecture ![](https://i.imgur.com/il5iIuR.png) #### Language support - Node.js - Java - Python - C# - Go - PowerShell #### Pricing - Number of requests - Duration Tips: - Lambda scales out automatically - Lambda functions are independent, 1 event = 1 function - Lambda is serverless - Know what services are serverless - Lambda functions can trigger other lambda functions, 1 event can = x functions trigger other functions - Architectures can get extremely complicated, AWS X-ray allows you to debug what is happening - Lambda can do things globally, you can use it to backup S3 buckets to other S3 buckets etc - Know your triggers (RDS can not trigger lambda) ### Overview of our serverless website ![](https://i.imgur.com/0K7wFfI.png) ### Serverless Apllication Model(SAM) - CloudFormation extension optimized for serverless applications - New types: - functions - APIs - tables - Supports anything CloudFormation supports - Run serverless applicaitons locally - Package and deploy using CodeDeploy ![](https://i.imgur.com/1xjyW7o.png) ```shell= sam init sam build sam deploy --guided ``` ### Elastic Container Service (ECS) #### What are containers and docker - A container is a package that contains an application, libraries, runtime, and tools required to run it - Run on a conrtainer engine like **Docker** - Provides the **isolation** benefits of virtualization with less overhead and faster starts than VMs - Containerized applications are **portable** and offer a consistent environment. ![](https://i.imgur.com/ShoXxR0.png) ![](https://i.imgur.com/cJ82e9N.png) #### Components - Cluster Logical collection of ECS resources - either ECS EC2 instances or Fargete instances. - Task Definition Define your application. Similar to a Dockerfile but for running containers in ECS. - Container Definition Inside a task definition, it defines the individual containers a task uses. Controls CPU and memory allocation and port mappings. - Task Single running copy of any containers defined by a task definition - Service Allows task definitions to be scaled by adding tasks. Defines min and max values. - Registry Storage for container images. #### Fargate - **Serverless** container engine - Eliminates need to provision and manage servers - Specify and pay for resources per application - Works with both **ECS** and **EKS** - Each workload runs in its own kernel - Isolation and security - Choose EC2 instead if: - Compliance requirements - Require broader customization - Require GPUs #### EKS - Elastic Kubernetes Service - K8s is **open-source** software that lets you deploy and manage containerized applications at scle - Same toolset on-premises and in cloud - Containers are grouped in **pods** - Like ECS, supports both EC2 and Fargate - Why use EKS? - Already using K8s - Want to migrate to AWS #### ECR - Managed Docker container registry - Store, managem and deploy images - Integrated with ECS and EKS - WOrks with on-premises deployments - Highly available - Integrated with **IAM** - Pay for storage and data transfer #### ECS + ELB = ❤️ ![](https://i.imgur.com/GemN9yj.png) - Distributed traffic evenly across tasks in your service - Supports ALB, NLB, CLB - Use ALB to route HTTP/HTTPS (layer 7) traffic - Use NLB or CLB to route TCP (layer 4) traffic - Supported by both EC2 and Fargate launch types - ALB allows: - Dynamic host port mapping - Path-based routing - Priority rules - ALB is recommended over NLB or CLB #### ECS Security ![](https://i.imgur.com/H2Ar5Fe.png) #### Diagram of ECS objects and how they relate ![](https://i.imgur.com/JiCAwXc.png)