Artem Arkhipov, Lead Web Developer at Techmagic
Backend as a Service
Function as a Service
Rich client app
User provisioning
Cloud database
Client app
API Gateway
Function 1
Function 3
Function 5
Function 2
Function 4
Function ...
- Event-driven
- Pay as you go
- Less about infrastructure
more about code
- Burst auto-scaling
AWS
MICROSOFT
IBM
Supported languages:
Execution time:
15 minutes
Resources available:
128 - 3008 MB memory
500 MB virtual /tmp folder
1024MB
Pricing example:
Free: 400 000 seconds and 1000000 requests Then: 0.000001667$ per 100ms exec time
0.20$ per 1000000 requests
const smthng = require('smthng');
exports.handler = function(event, context, callback) {
const val1 = event.key1 || 0;
const val2 = event.key2 || 0;
const result = sum(val1, val2);
callback(null, result);
}
function sum(a, b) { return a+b };event
context
callback
Event data
Information about current executing
Function used to pass err or data to caller
vs
//create some dumb load on machine
for (let i = 0; i <= 100000; i++) {
let to = setTimeout(() => {
let val = Math.random()*Math.random();
clearTimeout(to);
if (i === 100000) {
callback(val);
}
}, 4)
}5 users online
50 users online
Cold container, just spinned up, its first invocation
Warm container, is ready to immediately handle event
Busy container, function is executing just now
You still pay only for execution time
( it is not official terminology )
Cold invocations usually take a bit more time
No events for a quite long time
Load is low
Load increases
Cristiano Ronaldo twitted a link to your app
By default You can have up to 1000 concurrent executions
But if you really need, AWS will increase limits for free
But, unfortunately, nobody liked it:
And some time later:
- AWS automatically creates and destroys containers itself
- Remember that you can not depend on container reuse
- Cold starts are longer than warm, it depends on initialization time and size of your code (zip archive).
- Your functions should be stateless
- You can run background processes, keep database connections, etc if they are outside of your handler function
- If Cristiano tweets your app - AWS Lambda saves you
API Gateway
- Your API
- Web-hooks from 3d party services (git, jira, payments, etc)
S3 Events
- Uploaded files processing (image cropping, file converting)
Cloudwatch events and logs
- Scheduled tasks (report generating, automated backups)
- Infrastructure management
- Log analysis
DynamoDB Table updates
SES activities
SNS Notifications
and more...
$ npm install -g serverless$ sls create --template aws-nodejs my-serviceInstall
Create service
$ cd my-service$ sls deployDeploy service
High level overview of the solution
- Remeber to unref child processes and use /tmp dir as cwd
- Binaries should be compiled for matching version of linux
- Don't exceed package limitations
@serverless.ukraine
#makeserverless
Artem Arkhipov, Lead Web Developer at Techmagic
ar.arkhipov@gmail.co
skype: tamango92
twitter: ar_arkhipov