Serverless Architecture
A Valentine's Day Love Story!
Linda Nichols
@lynnaloo
Norfolk.js
norfolkjs.org
RevolutionConf
Virginia Beach, VA
Happy Valentine's Day!
@lynnaloo
Today you're going to fall in love with Serverless Architecture...
But first, you have to break-up with your servers
@lynnaloo
@lynnaloo
This story has all of the pieces of a typical romance:
-
Break-ups and decoupling
-
Commitment (and no-commitment)
-
Highly cohesive relationships
-
High availability and dedication
-
Support and growth
But first, what is "serverless"* architecture?
@lynnaloo
* "Serverless" is just a catchy, made-up, marketing term.
(Kind of like, "Cloud")
@lynnaloo
Serverless Architecture?
It isn't about a platform or compute product...
@lynnaloo
Serverless Architecture?
It's about the events!
@lynnaloo
Serverless Architecture?
Serverless Architecture is an event-driven system that uses remote functions (likely via a a FaaS product) without concern for the operations of the containers that execute the code.
@lynnaloo
Functions-as-a-Service (FaaS)
-
Building block of Serverless Architecture
-
Stateless and ephemeral
-
Functions run in containers that you don't manage
-
Removed complexity of building infrastructure
-
You only pay for the functions that you use
@lynnaloo
@lynnaloo
Your code could be completely free...
@lynnaloo
Functions-as-a-Service (FaaS)
In the cloud...
Serverless Architecture
-
Storage
-
IoT
-
Database Actions
-
API Gateway
-
Queues and Topics
-
Logging
@lynnaloo
Functions can be triggered by other cloud services
Functions are Microservices
-
Responsible for one specific task
-
Lightweight and fast
-
Reusable
-
Deployed independently
-
Not dependent on other services
-
Work together to power applications
@lynnaloo
(or nanoservices)
@lynnaloo
Did someone say decoupling?
@lynnaloo
Your perfect match!
Serverless Architecture
-
Dedicated
-
Flexible
-
Supportive
-
Resilient
-
Growth potential
-
Speaks many languages!
What if I'm scared of commitment?
@lynnaloo
@lynnaloo
Most platforms have similar services...
So, there's not much commitment!
Relationship Counseling
@lynnaloo
Embrace frameworks!
Serverless Framework:
-
Open-source
-
Abstracts and automates provider-specific tasks
-
Multi-provider plugin system
-
Scaffold and deploy using CLI
@lynnaloo
Get started.
# Install serverless cli
$ npm install serverless -g
# Create AWS Service
$ serverless create --template aws-nodejs --path cat-name-service
# Change into the service directory
$ cd cat-name-service
# Deploy to cloud provider
$ serverless deploy -v
cat-name-service/
package.json
serverless.yml
handler.js
dog-name-service/
package.json
serverless.yml
handler.js
@lynnaloo
Configure Service and Events.
#serverless.yml
service: cat-name-service
provider:
name: aws
runtime: nodejs6.10
functions:
catName:
handler: handler.getCatName
events:
- http:
path: cats/name
method: get
@lynnaloo
Create Handler.
'use strict';
const catNames = require('cat-names');
function getCatName(event, context, callback) {
callback(null, { payload: `Your cat name is ${catNames.random()}.` });
}
module.exports.getCatName;
(then package and/or deploy it!)
@lynnaloo
'use strict';
const catNames = require('cat-names');
const AmazonDb = require('amazon-db-module');
function getCatName(event, context, callback) {
const amazonDb = new AmazonDb();
const catName = catNames.random();
amazonDb.update(catName);
callback(null, { payload: `Your cat name is ${catName}.` });
}
module.exports.getCatName;
'use strict';
const catNames = require('cat-names');
const GoogleDb = require('google-db-module');
function getCatName(request, response) {
const googleDb = new GoogleDb();
const catName = catNames.random();
googleDb.update(catName);
return response.status(200).send(`Your cat name is ${catName}.`);
}
module.exports.getCatName;
@lynnaloo
Demo Time!
@lynnaloo
github.com/lynnaloo/valentines-day-bot
Mention @thesecatstweet in a tweet with the hashtag #happyvalentinebot
Demo Time!
@lynnaloo
github.com/lynnaloo/valentines-day-bot
Thank You!
@lynnaloo
Serverless Architecture: A Valentine's Day Love Story
By Linda Nichols
Serverless Architecture: A Valentine's Day Love Story
Swiftkick Training Serverless Architecture Webinar
- 1,462