Serverless

on AWS

 

What, why, how in less than 10 slides

Serverless doesn't mean no servers.

You just don't have to worry about them.

Bare

Metal

VMs

App. Servers

Serverless

Hetzner

DigitalOcean

Heroku

AWS Lambda

 /**
  * This is an example of a controller aka handler.
  */
 module.exports.handler = async function registerUserHandler(event, context, callback) {    
     const { name, email, country } = event.body; // This is raw input directly from a client
     const userId = await db.save({ name, email, country });

     events.emit(USER_REGISTERED, userId);

     callback(null, {
         statusCode: 200,
         headers: {},
         body: {
           success: true,
           response: { userId, name, email, country }
         }
     })  
 }
 $ curl -X POST \ 
     -D '{\"name\":\"Kostas\",\"email\":\"konmpar@gmail.com\",\"country\":\"GR\"}' \
     https://a.domain.com/users

 /**
  * Response:
  * 
  * {
  *   success: true,
  *   response: {
  *     userId: 321,
  *     name: "Kostas",
  *     email: "konmpar@gmail.com",
  *     country: "GR"
  *   }
  * }
  */
 service: serverless-example

 provider:
   name: aws
   runtime: nodejs4.3
   environment:
     DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}

 functions:
   create:
     handler: users/register.handler
     events:
       - http:
           path: users
           method: post
           cors: true

 resources:
   Resources:
     UsersDynamoDbTable:
       Type: 'AWS::DynamoDB::Table'
       DeletionPolicy: Retain
       Properties:
         AttributeDefinitions:
           -
             AttributeName: id
             AttributeType: S
         KeySchema:
           -
             AttributeName: id
             KeyType: HASH
         ProvisionedThroughput:
           ReadCapacityUnits: 1
           WriteCapacityUnits: 1
         TableName: ${self:provider.environment.DYNAMODB_TABLE}

Infrastructure based on events

 

* API Gateway

* DynamoDB record change

* S3 file contents change

* Time change (cron)

* Plus much more

All these can trigger a Lambda Function

Pros:

* Cost effective

* Auto-scaling

* Many many many things out of the box

 

Cons:

* Vendor lock-in

* Not exactly simpler

* Development experience is still.. mehh..

kostasbariotis.com

I'm

Thank you!

😎

serverless-on-aws

By Kostas Bariotis

serverless-on-aws

What, why, how in less than 10 slides

  • 1,502