Getting started with Serverless
What is Serverless Application?
Resources without provisioning and operations.
What is a Microservice?
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.
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?
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.
Cognito
Authentication / Authorization as a service.
… 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.