Getting started with Serverless
9/20/2019
Reading time: 3 mins

Getting started with Serverless

What is Serverless Application?

Resources without provisioning and operations.

Serverless Computing


What is a Microservice?

Image result for microservices


Why?

  • Auto-scaling
  • Fault-Tolerant by design
  • Pay-as-you-go
  • Quick and easy to develop? depends..

When?

It is wise to consider when to think serverless.

  • Workloads with irregular access patterns
  • Workloads with short execution times
  • Automation

What is AWS Lambda?

AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of the Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that code. It was introduced in November 2014.

Image result for aws lambda


So that is serverless. The computing resource that automagically summons to respond to an event. But is that all?


What else comprises of Serverless Application?

Serverless


API gateway

API gateway unifies API endpoints for the resources / even methods that are scattered in the internet. So if you have multiple lambda functions, which is certain if you are using Serverless architecture, API Gateway will be a must.



S3 buckets

If you need to keep files / data (unstructured). S3 is a cheap service for that. It is also very useful to version your Lambdas and generally deploying your functions.


DynamoDB

NoSQL db from AWS for your data needs.

Key value store.

Image result for dynamodb


Cognito

Authentication / Authorization as a service.

Image result for cognito aws signup sign in


… etc..


Lost?

As a beginner its very easy to get lost and never think again about it because the architecture is a lot of ops work than dev work. But you are a dev.


Where to start?

For developers there are some options to get started with serverless application development in no time*.


Serverless Framework

  • Easiest to get started,
  • does most of the simple tasks out of the box, like namespacing, versioning, deployments, staging, monitoring.
  • Very easy to configure (until it get hard).
  • Plugins available to support further extensions.

Getting started

Installation


# Install the serverless cli
npm install -g serverless


# Create and deploy a new service/project
serverless

Serverless.yml


service: contact

app: anilmaharjan-com-np

org: dejavu1987

Configure Environment


provider:
  name: aws
  runtime: nodejs10.x
  region: eu-central-1
  environment:
    STRIPE_SECRET_KEY: 'sk_test_xxxxxxxxxx'
    DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage, 'dev'}


Lambda Function


functions:
  contact:
    handler: handler.post
    events:
      - http:
          path: contact
          method: post
          cors: true

Other

  • Managing resources
  • Configuring plugins
  • API Gateway

Alternatives to Serverless Framework?

SAM: An extension to CloudFormation for Serverless applications.

Terraform: Thirdpart Infrastructure on code.

Previous
Intel Edison
Next
Ingress – All you need to know
© 2024 Anil Maharjan