What is a Serverless Architecture
- Is a way to build and run applications and services without having to manage infrastructure and scale, maintain servers.
- Your application still runs on servers, but all the server management is done by AWS
- AWS offers technologies for running code, managing data, and integrating applications, all without managing servers
- It feature automatic scaling, built-in high availability, and a pay-for-use billing model to increase agility and optimize costs.
- Serverless applications start with AWS Lambda, natively integrated with over 200 AWS services and software as a service (SaaS) applications
- Serverless does not mean there are no servers. it means you just don’t manage / provision / see them.
Serverless Services in AWS
- AWS Lambda
- AWS Fargate
- AWS Cognito
- AWS API Gateway
- Amazon S3
- AWS SNS & SQS
- AWS Kinesis Data Firehose
- Aurora Serverless
- Step Functions
What is AWS Lambda
- Lambda is a compute service that lets you run code without provisioning or managing servers.
- Lambda runs your code on a high-availability compute infrastructure.
- AWS performs all of the administration of the compute resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging
- you can run code for virtually any type of application or backend service
- AWS Lambda runs your code on a high-availability compute infrastructure
- AWS Lambda executes your code only when needed and scales automatically.
- You pay only for the compute time you consume – No charge when your code is not running.
|EC2 Instance||AWS Lambda|
|Virtual Servers in the Cloud||Virtual functions – no servers to manage!|
|Limited by RAM and CPU||Limited by time – short executions|
|Continuously running||Run on-demand|
|Scaling means: To add or remove servers||Scaling is automated!|
Benefits of AWS Lambda
- Easy Pricing
- Pay per request and compute time
- Free tier of 1,000,000 AWS Lambda requests and 400,000 GBs of compute time
- No servers to manage
- Continuous scaling
- Integrated with the many AWS services
- Integrated with many programming languages
- Easy monitoring through AWS CloudWatch
- Easy to get more resources per functions
- Increasing RAM will also improve CPU and network!
AWS Lambda language support
- Java (Java 8 compatible)
- C# (.NET Core/ Powershell)
- Custom Runtime API
AWS Lambda Functions Configuration
- IAM role (execution role)
- This is the role that AWS Lambda assumes when it executes the Lambda function on your behalf.
- Handler name
- The handler refers to the method in your code where AWS Lambda begins execution.
- AWS Lambda passes any event information, which triggered the invocation, as a parameter to the handler method.
- Language Selection
- Write your source code
Lambda Function – Services it can access
- Lambda functions can access
- AWS Services running in AWS VPCs (Ex. Redshift , ElastiCache, RDS instances)
- Non-AWS Services running on EC2 instances in an AWS VPC
- Additional configuration will be required for VPC access (Security group and subnet IDs)
- AWS Lambda runs your function code securely within an internal AWS VPC (not your VPC) by default.
- This VPC has connectivity to AWS services and the internet.
- You can configure a lambda function to connect to private subnets (DBs, Cache instances, or Internal services) in your VPC in your accounts
- To enable your Lambda function to access resources inside your VPC:
- Provide additional VPC-specific configuration information that includes VPC subnet IDs and security group IDs
- Lambda will then create an ENI for each subnet and security group attached to the Lambda function
Invoking Lambda Functions
- On-demand Lambda function invocation
- Amazon API Gateway
- Load Balancer
- Web/Mobile application
- Using SDKs
- Scheduled events
- Regular, scheduled basis.
- Cron Jobs
- Event Source Mapping
- An event source is the AWS service or custom application that publishes events,
- A Lambda function is the custom code that processes the events.
- Event sources publish events that cause the Lambda function to be invoked
Supported AWS event sources
- Amazon S3
- Amazon DynamoDB
- Amazon Kinesis Streams
- Amazon Simple Notification Service
- Amazon Simple Email Service
- Amazon Cognito
- AWS CloudFormation
- Amazon CloudWatch Logs
- Amazon CloudWatch Events
- AWS CodeCommit
- AWS Config
- Amazon Alexa
- Amazon Lex
- Amazon API Gateway
- AWS IoT Button
- Amazon CloudFront
- Amazon Kinesis Firehose
- Amazon SQS
Use Cases of AWS Lambda
- You have a photo sharing application. Your application upload photos, and the application stores these user photos in an Amazon S3 bucket.
- Lambda function triggers for each photo upload and resize it for web. Mobile and tab size
AWS Lambda Limits
- Memory allocation: 128 MB – 3008 MB (64 MB increments)
- Maximum execution time: 900 seconds (15 minutes)
- Environment variables (4 KB)
- Concurrency executions: 1000 (can be increased)
- Lambda function deployment size (compressed .zip): 50 MB
- Size of uncompressed deployment (code + dependencies): 250 MB
- Can use the /tmp directory to load other files at startup
- Size of environment variables: 4 KB
Monitoring and Pricing
- AWS Lambda automatically monitors Lambda functions on your behalf, reporting metrics through Amazon CloudWatch
- Log Captured in CloudWatch in Log Group
- Pricing: https://aws.amazon.com/lambda/pricing/