Building serverless app_using_aws_lambda_b4usolution
-
Upload
hoa-le -
Category
Technology
-
view
141 -
download
0
Transcript of Building serverless app_using_aws_lambda_b4usolution
Agenda
1. Serverless Architectures
2. Cons & Pros
3. What is AWS Lambda?
4. Building Application with AWS Lambda
5. AWS Lambda’s use cases
6. Demo
Disadvantage
• Design provision and scale a bunch of servers• Manage operation updates, apply security patches• Monitor all the infrastructure for performance and availability
When having a large number of images
Need more server instances to handle uploaded images
Serverless Architectures
Function as a Service(execute your custom code)
Backend as a Service(third party services)
Serverless Architectures
Backend as a Service / BaaS
3rd party applications / services (in the cloud) that your applications use to manage server-side logic and state
Cloud accessible databases
…
Authentication services
AWS Cognito
Traditionally deploy server-side software
Host Instance (Container)
Application (Process) Operation
Operation
Operation
Function as a Service / FaaS
Host Instance (Container)
Application (Process) Operation
Operation
Operation
FaaS Platform
Function as a Service / FaaS
Operation
Operation
Operation
Operation
Each operation listens to specific event
Ephemeral Container
Function as a Service / FaaS
FaaS Platform
Operation
Operation
Operation
Operation
Serverless Architectures - Examples
Example 1: The architecture of an ecommerce app
DatabaseClient App Server
The traditional architecture will look like this:
Serverless Architectures - Examples
Purchase Database
Client
With a Serverless architecture, this may look like this:
Authentication Service
API Gateway
Purchase Function
Search Function
Product Database
1
2
4
5
3
Serverless Architectures - Benefits
Reduced Development Cost
Scaling CostsFunction as a Service / FaaS
Backend as a Service / BaaS
BaaS – Reduced Development Cost
APPLICATION BUSINESS LOGIC
DATA PROCESSING / MANAGEMENT
…
Users Databases PUB SUB Files
BACK-END
Serverless BaaS services are provided via the use of custom SDKs and APIs, using these such services reduces development cost
Backend as a Service
FaaS – Scaling Costs
Horizontal scaling is completely automatic, elastic, and managed by the provider
Only pay for the compute that you need
FaaS – Scaling Costs
OCCASIONAL REQUESTS INCONSISTENT TRAFFIC
02468
Nu
mb
er o
f R
equ
ests
Minutes
Number of Requests
Number of Requests
0
100
200
300
Nu
mb
er o
f R
equ
ests
Minutes
Number of Requests
Number of Requests Require more CPU
Mean CPU usage over an hour is 0.1%. The application traffic is bursty
Examples
Serverless Architectures – Drawbacks
Problems due to third-party API system
• Vendor control
• Multitenancy problems
• Vendor lock-in
• Security concerns
Lack of operational tools
• Dependent on vendors for debugging and monitoring tool
Architectural complexity
• Decisions about how the small function should be
Implementation drawbacks
• Integration testing Serverless Apps is hard
• Execution Duration
• Startup Latency
• Testing
Comparison
Feature AWS Lambda Google Cloud Azure Functions
Scalability & availability Automatic scaling Automatic scaling Automatic scaling
Supported languages JavaScript, Java, Python, C# Only JavaScriptC# and JavaScript (preview of F#, Python, Batch, PHP, PowerShell)
Max concurrent functions 1000 invocations 400 invocations (but can be increased) No limit
Max function duration 300 seconds 540 seconds 5 minutes
Event-drivenS3, SNS, SES, DynamoDB, Kinesis, CloudWatch, Cognito, API Gateway, CodeCommit, etc.
Cloud Pub/Sub or Cloud Storage Object Change Notifications
WebHook, GitHub WebHook, Queue, Http, ServiceBus Queue, Service Bus Topic, Timer triggers
Pricing
Invocations: 1M Invocationsfor free (Free Tier), then $0.20/1M
InvocationsGB-s: 400,000 GB-s for free, then $0.00001667 per GB-s
Invocations: 2M Invocations for free,then $0.40/1M InvocationsGB-s: 400,000 GB-s for tree, then $0.0000025 per GB-sGHz-s: 200,000 for tree tire, then $0.0000100 per GHz-s
Invocations: 1M Invocationsfor free (Free Tier), then $0.20/1M
InvocationsGB-s: 400,000 GB-s for free, then $0.000016 per GB-s
What is AWS Lambda?
An implementation of Serverless Architecture
Provides FaaS container to run your custom code in response to events.
Building Lambda Functions
Authoring code for your Lambda
function
Uploading code and creating
Lambda functions
Monitoring and troubleshooting
Building Lambda FunctionsAuthoring code for your Lambda function
1. Language you choose to write your Lambda function code.
2. AWS Lambda runtime provides some of the libraries and you must upload any additional libraries that
you use.
Languages Tools and Options for Authoring Code More Information
Node.js • AWS Lambda console• Visual Studio, with IDE plug-in
• The AWS Toolkit also creates the deployment package• You can use the console if the languages you choose do not
require compilation, the code is saved in a single file, and it does not depend on any libraries.
Java • Eclipse, with AWS Toolkit for Eclipse
C# • Visual Studio, with IDE plug-in• .NET Core
Python • AWS Lambda console
Building Lambda FunctionsDeploying Code and Creating a Lambda Function
1. Creating a Deployment Package
2. Creating a Lambda Function
3. Uploading a Deployment Package
4. Testing a Lambda Function
Building Lambda FunctionsMonitoring and Troubleshooting
1. Sign in to the AWS Management Console and open the AWS Lambda console
2. On the Functions page, choose the function name and then choose the Monitoring tab
Building applications with AWS Lambda
• Core Components of AWS Lambda:
Event Sources Lambda Functions
• An event source is the AWS service or custom application that publishes events• A Lambda function is the custom code that processes the events
Building applications with AWS Lambda
• Event Source Mapping
AWS services
Custom application
Regular AWS services(All other AWS services do not use stream event source)
Stream-based services(Amazon Kinesis Streams and Amazon DynamoDB Streams)
Event sources
Building applications with AWS Lambda
• Event Source Mapping for AWS Services
o Example – Amazon S3 Pushes Events and Invokes a Lambda Function
• Need to grant the event source the necessary permissions using a resource-based policy
Building applications with AWS Lambda
• Event Source Mapping for AWS Stream-based Services
o Example – AWS Lambda Pulls Events from an Amazon Kinesis Stream and Invokes a Lambda Function
• AWS Lambda needs your permission to poll the stream and read records
Building applications with AWS Lambda
• Event Source Mapping for Custom Applications
o Example – Custom Application Publishes Events and Invokes a Lambda Function
• No pre-configuration required• Don’t have to set up event source mapping• The event source use the AWS Lambda
Invoke API• Must allow cross-account permissions in
the permissions policy associated with the Lambda function in case the application and Lambda function are owned by difference accounts
What can you build with AWS Lambda?
• Data Processingo Real-time File Processing
o Real-time Stream Processing
o Extract, Transform, Load
• Backendso IoT Backends
o Mobile Backends
o Web Applications
Demo 1• Create a Lambda function to generate thumbnail images when there are photos
uploaded to a S3 Bucket
References• AWS Lambda Developer Guide: http://docs.aws.amazon.com/lambda/latest/dg
• Introduction to AWS Lambda - Serverless Compute on Amazon Web Services: https://www.youtube.com/watch?v=eOBq__h4OJ4
• AWS re:Invent 2014 | (MBL202) NEW LAUNCH: Getting Started with AWS Lambda: https://www.youtube.com/watch?v=UFj27laTWQA
• Technical Introduction to AWS Lambda - Serverless Compute on AWS: https://www.youtube.com/watch?v=QzipnZzAQEk
• Serverless Architectures - Martin Fowler
• …