AWS Deployment using the Serverless Framework

AWS Deployment through Serverless - K.Merino

Kim Merino

Senior Analyst, Accenture

AWS Deployment through Serverless - K.Merino

AWS

Amazon Web Services

  • Used by 2/3 of the cloud services*
  • Designed to be serverless so developers can focus on business logic
  • User-friendly point-and-click deployment
  • Large library of application resources (database, EC2, API gateways, identity management)
  • Lambda functions are the meat of an AWS application; they contain the logic needed for APIs to work

AWS Deployment through Serverless - K.Merino

AWS Ughs

  • Getting Lambda to talk with API Gateway is hard
  • Difficult to implement changes in lambda
  • No control of both code and deployment in one place
  • No central control of AWS resources

AWS Deployment through Serverless - K.Merino

Ugh, that code editor

BARF

AWS Deployment through Serverless - K.Merino

Enter the magic of Serverless

AWS Deployment through Serverless - K.Merino

Configurable

Use of variables for custom deloyments

service: todos-service
custom: ${file(../config/${opt:stage, self:provider.stage}.yml)}
service: "my-serverless-app"
region: "us-west-2"
stage: "dev"
todosBucket: "todos-bucket-dev"
userBucket: "user-bucket-dev"
service: "my-serverless-app"
region: "us-east-1"
stage: "test"
todosBucket: "todos-bucket-test"
userBucket: "user-bucket-test"

Deploy to east region to a test environment

Deploy to west region to a dev environment

AWS Deployment through Serverless - K.Merino

One File to Rule Them All

AWS Deployment through Serverless - K.Merino

The yaml file

service: todos-service
custom: ${file(../config/${opt:stage, self:provider.stage}.yml)}

provider:
  name: aws
  runtime: nodejs4.3
  region: ${self:custom.region}
  stage: dev
  iamRoleStatements:
   - Effect: "Allow"
     Action:
       - "lambda:InvokeFunction"
     Resource: ["*"]
   - Effect: "Allow"
     Action:
       - execute-api:InvokeFunction
     Resource: "arn:aws:execute-api:${self:custom.region}:*:*"

functions:
  GetTodos:
    handler: handler.getTodos
    events:
     - http:
         path: todos/create
         method: get
         cors: true

resources:
  Resources:
    TodosBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:custom.todosBucket}

Easy integration with AWS Lambda

functions:
  GetTodos:
    handler: handler.getTodos
    events:
     - http:
         path: todos/create
         method: get
         cors: true
module.exports.getTodos = (event, context, callback) => {
  const response = {
    statusCode: 200,
    headers: {
        "Access-Control-Allow-Origin" : "*",
        "Access-Control-Allow-Credentials" : true
    },
    body: JSON.stringify({
      message: 'Here are your todos',
      input: event,
    }),
  };

  callback(null, response);

};
handler.js
yaml file

This becomes our lambda

AWS Deployment through Serverless - K.Merino

Lambda code and deployment all in one place

AWS Deployment through Serverless - K.Merino

Contact Info

@ladycornfish

AWS Deployment through Serverless - K.Merino

Intro

By Kim Merino

Intro

  • 237
Loading comments...

More from Kim Merino