aws lambda and serverless cloud
TRANSCRIPT
AWS LAMBDAAnd The Serverless Cloud
Muhammet ArslanSoftware Developer @Sony
This document prepared for BBS on 14th May, 2016 Sony
WHAT İS LAMBDA ? WriteYour Code
And That’s All!Never think about;
ServersOr
OsOr
ScalabilityOr
Durability
HOW LAMBDA WORKS ?
Write / Upload your code to AWS Lambda
Trigger the AWS from other AWS
services like S3, Api
Gateway, Dynamodb…
Lambda only runs your code
when triggering and
uses only compute resources needed
Pay for the compute time
you use1
A CLEAR EXAMPLE ?
Photo is uploaded to S3 by web server
Lambda automaticaly triggered by AWS S3 service
Deployed «Lambda» code runs and resizes the photo
BENEFITS OF AWS LAMBDA
Serverless Secure
Auto-ScaledPay only running
(sec)
LAMBDA EXECUTION ENVIROMENT• Linux kernel version : 4.1.19-24.31.amzn1.x86_64
Supporting Languages and RUNTIME Versions
• Node.js: v0.10.36, v4.3.2 (recommended)• Java: Java 8• Python: Python 2.7
Already-Installed Libraries• Node.js: Imagick, Aws SDK • Java: NOTHING!• Python: AWS SDK (boto3)
AWS SERVİCES AS EVENT SOURCES
S3DynamoDB
Kinesis
SNS
SES
COGNITO
CloudWatch
CloudFormation
Config
HOW A LAMBDA FUNCTION IS INVOKED
The Push Event Model• Publish events to AWS Lambda and Directly invoke
S3
CognitoSNS
ECHO
Custom App
HOW A LAMBDA FUNCTION IS INVOKED
The Pull Event ModelAWS Lambda polls an event source and invokes your Lambda function when the service detects new events
DynamoDBKinesis
LIM
ITAT
ION
S O
F AW
S LA
MBD
AEphmeral Disk Capacity512 MBNumber of processes and threads1024Maximum execution duration per request
300 Sec
Invoke request body payload size (RequestResponse)6 MBInvoke request body payload size (Event)128 KInvoke response body payload size (RequestResponse)6 MB
AWS LAMBDA AND NETFLIXDelivered 7 million hours of video to 50 million customers in 60 countries per quarter
Studios pushes videos
to Netflix frequently
Before Lambda!
Over the Santa systems’ Netflix process file (5
minutes chunks for paralel processing)
and repackage
And deploy to watched by
users!
After Lambda!
Studios pushes videos
to S3, via Aspera
S3 Trigger lambda to start the
process ( process the file,
repackage and deploy)
REAL LIFE EXAMPLE
The developed code, on the Sony Bbs Meeting, uploaded to,http://github.com/geass/sony-bbs-lambda
• User uploads an image from administration area (was developed with PHP)• Administration system uploads image to AWS S3 BUCKET• S3 Invokes the lambda to fetch & resize Images• Lambda fetch & resize & upload images to same bucket• And Show the resized versions on Web Site
HOW AWS COSTS YOUR LAMBDA EXECUTES?
Request Duration• First 1 million
requests per month are free
• $0.20 per 1 million requests thereafter
Duration is calculated from the time your code begins executing until it returns or otherwise terminates, rounded up to the nearest 100ms.
«The price depends on the amount of memory you allocate to your function. »
HO
W A
WS CO
STS
YOU
R LA
MBD
A D
URA
TIO
NS?
Memory (MB) Free tier seconds per month Price per 100ms ($)
128 3,200,000 0.000000208192 2,133,333 0.000000313256 1,600,000 0.000000417320 1,280,000 0.000000521384 1,066,667 0.000000625448 914,286 0.000000729512 800,000 0.000000834576 711,111 0.000000938640 640,000 0.000001042704 581,818 0.000001146768 533,333 0.000001250832 492,308 0.000001354896 457,143 0.000001459960 426,667 0.0000015631024 400,000 0.0000016671088 376,471 0.0000017711152 355,556 0.0000018751216 336,842 0.0000019801280 320,000 0.000002084
1344 304,762 0.0000021881408 290,909 0.0000022921472 278,261 0.0000023961536 266,667 0.000002501
EXAM
PLE
COST
ING
OF
AWS
LAM
BDA
If you allocated 512MB of memory to your function, executed it 3 million times in one month, and it ran for 1 second each time, your charges would be calculated as follows:
Monthly compute chargesThe monthly compute price: $0.00001667 per GB-s The free tier : 400,000 GB-s.
Total compute (seconds) = 3M * (1s) = 3,000,000 seconds512MB/1024 = 1,500,000 GB-s1,500,000 GB-s – 400,000 free tier GB-s = 1,100,000 GB-s
Monthly compute charges:1,100,000 * $0.00001667 = $18.34
Monthly request charges
The monthly request price is $0.20 per 1 million requests and the free tier provides 1M requests per month.
3M requests – 1M free tier requests = 2M Monthly billable requests
Monthly request charges:2M * $0.2/M = $0.40
TotalTotal charges = Compute charges + Request charges:
$18.34 + $0.40 = $18.74 per month
http://github.com/geass/sony-bbs-lambda
Muhammet ArslanSoftware Developer @Sony
Thank You!