Piotr Zientara
"Writing your first Amazon lambda using JS"
2016-09-14
Today morning...
This presentation plan
What is AWS Labmda?
How to implement it?
Evaluation of the tool
What is an AWS Lambda?
code that can be run on your behalf using AWS infrastructure
written in supported language (Node.js, Java, and Python)
that can be used as:
event-driven compute service where AWS Lambda runs your code in response to events
compute service to run your code in response to HTTP requests using Amazon API Gateway or API calls made using AWS SDKs.
How to start?
Have an AWS account
Have an idea
Have some time to read the docs or just listen to this presentation ;-)
Example lambda in Node.js
'use strict';
console.log('Loading event');
exports.handler = function(event, context) {
var hello = { "Hello":"World" }
// SUCCESS with message
context.done(null, hello);
};
Another example with params
console.log('Loading event');
exports.myHandler = function(event, context, callback) {
console.log("value1 = " + event.key1);
console.log("value2 = " + event.key2);
callback(null, "some success message");
// or
// callback("some error type");
})
What year do we have?
Why?
Let's follow this idea!
What is the year using in alterntive calendars? Eg. A.U.C. (Ab Urbe Condita), abbr. to Anno Urbis (AU) instead of post Christum natum abbr. to Anno Domini (AD)?
we can ask for year Ab WarsawJS Condita (WJS) with a parameter
Simple function with API Gateway (1/2)
Amazon Services > Lambda > Get started now
Configure function
write the body of the function
set the role
create function
test it
remember the region where is is created!
Simple function with API Gateway (2/2)
Setup gateway
API Gateway
get started -> create Gateway
resources -> create GET resource
test it
Hold up! Live coding session!
What can go wrong? ;-)
Is coding like philosophy?
Philosophy is like trying to open a safe with a combination lock: each little adjustment of the dials seems to achieve nothing, only when everything is in place does the door open.
Ludwig Wittgenstein
What might go wrong?
buckets confusion
POST requests get JSON
getting lost in the docs
setting the access policy wrong
be disappointed with the tests results
What I was expecting to be different?
Examples of using
My case on production project
creating a ZIP archive form files on Amazon S3 bucket and giving a link to the user
performance is important
simplicity and scalability is important
Strong sides of Amazon Lambda
scalable
cheap - 1000 000 requests a month for free
independent
STATS
Presentations
All: 77 (without invitations)
This year:
Polish: 22
English: 16
Social Networks
Facebook: likes 1090
Twitter: 283 followers
YouTube
Subscribed: 544 (356)
Viewed: 31 642 (+ 310% )
Hands up: +318
Shares: 129
Most popular talks this year!
This year organizers
Piotr Kowalski
Piotr Zientara
Katarzyna Grabowska
See you next month at WarsawJS#26 (second Wednesday of October)