Best Practices for Serverless Development

Let’s take a look at some Serverless best practices.

Serverless Guru
Mar 6, 2019 · 6 min read

Sections:

  • Selecting a cloud provider or two
  • Choosing a deployment framework
  • Leveraging fully managed services

Selecting a cloud provider or two

When it comes to Serverless development, it is even more important to make sure we select the right cloud provider for the job. The primary reason the decision is important comes down to the long term maintainability and scalability of your application.

  1. Google Cloud Platform (GCP)

Choosing a deployment framework

Serverless development is all about bringing multiple roles such as operations and development together. Serverless development translates to the Serverless developer writing automation and application code at the same time.

The benefits of this approach include:

  • High levels of automation
  • Multi-stage/multi-region environments for testing/production
  • Developers have a deeper understanding of the entire application

Organizing projects

How you structure your projects has always been an important factor in software development. Serverless development is no different. Let’s take a look at a basic structure for a well broken apart project.

src/
main.js <-- Lambda entry point
services/ <-- Business Logic
api.js
helpers/ <-- Reusable functions
util.js
resources/ <-- Native CloudFormation
general.yaml
general-ouputs.yaml
scripts/ <-- CI/CD scripts
test.bash
deploy.bash
serverless.yaml <-- Serverless Framework config
cloudbuild.yaml <-- Google Cloud Build CI/CD steps
package.json

Key directories:

  • src — Lambda code
  • resources — Native CloudFormation files to keep the serverless.yaml clean
  • scripts — CI/CD bash/python scripts

Key files:

  • serverless.yaml — Connects the lambda code and AWS resources together into a deployable stack
  • src/main.js — Entry point for our lambda functions
  • cloudbuild.yaml — Google Cloud Build CI/CD pipeline

Creating reusable templates

Code reusability is a significant part of software development. Thanks to the Serverless Framework and Amazon our infrastructure is now code. Enabling “infrastructure reusability” through the use of shared Serverless Framework templates.

$~: sls create --template aws-nodejs --path nodejs-project
$~: sls create --template <template> --path <project_name>

Python:

There is official template support for python 2.7 and python 3.x.

  • Python 3.xaws-python3

NodeJS:

There is official template support for NodeJS 8.x, NodeJS + TypeScript and NodeJS + ECMA Script.

  • NodeJS + TypeScriptaws-nodejs-typescript
  • NodeJS + ECMA Script aws-nodejs-ecma-script

Java:

There is official template support for Java with Maven and Java with Gradle.

  • Java with Gradle aws-java-gradle

Kotlin:

There is official template support for Kotlin with Maven, Kotlin with Gradle, and Kotlin with Gradle + NodeJS 🤯 🤯.

  • Kotlin with Gradleaws-kotlin-jvm-gradle
  • Kotlin with Gradle + NodeJSaws-kotlin-nodejs-gradle

More:

There is official template support for Groovy, Scala, CSharp, and FSharp.

  • Scala aws-scala-sbt
  • CSharpaws-csharp
  • FSharpaws-fsharp

But, wait there's even more.

You can also easily spin up the foundation for Serverless Plugins, Alexa skills, and even your custom templates!

Additional Reading:

Leveraging fully managed services

Fully managed services, give us the ability to accelerate application development while abstracting away the details which are not needed. For example, when you buy a car, you drive around without needing to know the internal workings of a combustion engine. Fully managed services are the mantra of Serverless development.

On the Amazon front:

  • Cognito — Authentication service supporting OAuth and OpenID
  • DynamoDB — NoSQL database
  • Aurora Serverless — Relational database for MySQL/PostgreSQL
  • Lambda — Cloud functions, a.k.a. glue code
  • API Gateway — Simple REST APIs
  • AppSync — GraphQL serverless back-end
  • S3 (Simple Storage Solution)— Blob storage and static website hosting
  • SES (Simple Email Service) — Sending emails
  • SNS (Simple Notification Service) — Pub/Sub messaging, send SMS
  • SQS (Simple Queue Service) — Decouple and scale Serverless applications
  • CloudFront — Caching and faster content delivery
  • ACM (Certificate Manager) — SSL certificates for HTTPS

On the Google front:

  • Google Cloud Build — create build triggers on GitHub/BitBucket to power the frontend and backend CI/CD pipelines

Additional Content:

What does Serverless Guru do?

Serverless Guru helps companies build scalable and cost-effective applications on the cloud. We help train companies on how to leverage IAC, serverless, and cloud-native services. We help migrate existing applications to the cloud and optimize existing applications on the cloud to be more cost-effective. We are a Serverless development partner and an AWS Consulting partner.

Image for post
Image for post

What did we miss?

When you leave your answer make sure to either comment below or tweet your answer to @serverlessgurux on Twitter.

Image for post
Image for post
https://www.serverlessguru.com

Ryan Jones

Founder — Serverless Guru

Serverless Guru

Serverless guides on your cloud journey

Serverless Guru

Written by

We can help you migrate to serverless, build serverless applications, and train your team on serverless best practices. https://www.serverlessguru.com

Serverless Guru

Serverless Guru exists to be a change agent and overall guide to companies around the globe whom are moving to serverless at scale. We help companies understand where serverless fits and where it doesn’t. Then we lay a proven roadmap to move them along in their serverless journey

Serverless Guru

Written by

We can help you migrate to serverless, build serverless applications, and train your team on serverless best practices. https://www.serverlessguru.com

Serverless Guru

Serverless Guru exists to be a change agent and overall guide to companies around the globe whom are moving to serverless at scale. We help companies understand where serverless fits and where it doesn’t. Then we lay a proven roadmap to move them along in their serverless journey

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store