#serverless
((SERVERLESS) => NO SERVERS FOR YOU TO MANAGE)
Mike Roberts
Serverless
FaaS
Serverless: It’s much much more than FaaS
Function as a Service
Blob storage
Serverless databases
Serverless Containers
Backend as a Service
exports.handler = function(event, context) {
context.succeed(“Hello, World!”);
};
def my_handler(event, context):
message = 'Hello {} {}!'.format(event['first_name'],
event['last_name'])
return {
'message' : message
}
package main
import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/lambda"
)
type MyEvent struct {
Name string `json:"name"`
}
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
return fmt.Sprintf("Hello %s!", name.Name ), nil
}
func main() {
lambda.Start(HandleRequest)
}
package example;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Hello implements RequestHandler<Integer, String>{
public String myHandler(int myCount, Context context) {
return String.valueOf(myCount);
}
}
The Serverless Framework is an open-source CLI for building and deploying serverless applications
Time to market
Operational Costs
Billing model
Economy of scale
Event-driven
Polyglot systems
High availability
I ♥ localhost
AWS Serverless Application Model prescribes rules for expressing Serverless applications on AWS.
https://github.com/awslabs/serverless-application-model
The AWS Serverless Application Model (SAM) is an abstraction layer in front of CloudFormation that makes it easy to write serverless applications in AWS. There is support for three different resource types: Lambda, DynamoDB and API Gateway. Using SAM Local, Lambda and API Gateway can be run locally through the use of Docker containers.
● Set of primitives (Build, Events, Serving)
● Solves for modern development patterns
● Implements learnings from Google, partners
● Ingredient or platform for OSS FaaS frameworks
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: simple
namespace: default
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
image: gcr.io/knative-samples/simple-app:latest
env:
- name: SIMPLE_MSG
value: "Hello GCP Next 2018!"
Blue-green deployment
apiVersion: serving.knative.dev/v1alpha1
kind: Route
metadata:
name: blue-green # Updating our existing route
namespace: default
spec:
traffic:
- revisionName: blue-green-00001
percent: 0
name: v1 # Adding a new named route for v1
- revisionName: blue-green-00002
percent: 100
# Named route for v2 has been removed, since we don't need it anymore
apiVersion: serving.knative.dev/v1alpha1
kind: Route
metadata:
name: blue-green # Updating our existing route
namespace: default
spec:
traffic:
- revisionName: blue-green-00001
percent: 50 # Updating the percentage from 100 to 50
- revisionName: blue-green-00002
percent: 50 # Updating the percentage from 0 to 50
name: v2
apiVersion: build.knative.dev/v1alpha1
kind: BuildTemplate
metadata:
name: kaniko
spec:
parameters:
- name: IMAGE
description: The name of the image to push
- name: DOCKERFILE
description: Path to the Dockerfile to build.
default: /workspace/Dockerfile
steps:
- name: build-and-push
image: gcr.io/kaniko-project/executor
args:
- --dockerfile=${DOCKERFILE}
- --destination=${IMAGE}
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: src-to-url
namespace: default
spec:
runLatest:
configuration:
build:
source:
git:
url: https://github.com/mchmarny/simple-app.git
revision: master
template:
name: kaniko
arguments:
- name: IMAGE
value: &image us.gcr.io/s9-demo/src-to-url:latest
revisionTemplate:
metadata:
labels:
knative.dev/type: app
spec:
container:
image: *image
imagePullPolicy: Always
env:
- name: SIMPLE_MSG
value: "Images, what images? I'm Knative-built!"
Source To URL
@mcolomer
marcelo.colomer@gft.com