Serverless Blog
all
guides & tutorials
user stories
operations & observability
engineering culture
news

3 Steps To Faster Serverless Development

written by  
  David Wells

One of the biggest pain points we hear from developers moving into the serverless world, is the slower feedback loop while developing.

In this post, I'm going to walk through some of the ways I speed up building and deploying live serverless services.

The serverless framework has a ton of hidden gems to speed up your dev cycle.

Lets explore!

1. Deploy changes faster with sls deploy function

Many users aren't aware of the serverless deploy function command and instead use serverless deploy each time their code has changed.

What is the difference?

sls deploy re-deploys the entire stack through cloud formation and can be noticeably slooowww.

On the flip side, sls deploy function only zips up the code (& any dependancies) and updates the lambda function only. This is much much faster than waiting for an entire stack update.

So, when developing you can use sls deploy function -f myFuncName for speedier code changes in your live AWS account.

One note: If you make any changes to serverless.yml config, like changing endpoint paths or updating custom resources, etc that will require a full sls deploy to update the entire stack.

If you have only make changes to your function code, sls deploy function -f myFuncName will work just fine and be much snappier.

# Redeploy entire stack through cloud formation
sls deploy

# Redeploy only the code + dependancies to update the AWS lambda function
sls deploy function -f myFuncName

2. Tail your live service logs

Debugging remote code in the serverless world can be tricky. Luckily console.log and lambda functions go together like peanut butter and jelly.

One of my favorite serverless framework commands is the sls logs command. It will pull the logs from your remote function directly into the terminal.

This is handy for debugging errors or inspecting what the event or context args contain.

It's even more useful when you tail the logs and get a live update as you are pinging your live functions.

# View logs of myFuncName and tail via -t flag
serverless logs -f myFuncName -t

I will pop open a new terminal window and run sls logs -f funcName -t and then ping my lambda function with Postman (or my UI) and live debug the function.

Having 2 terminal windows open and combining sls deploy function -f funcName for quicker code changes and watching the live logs with sls logs -f funcName -t is super easy to do and speeds up my feedback loop.

3. Offline Emulation

Now you might be asking, what about offline emulation? It's absolutely a way to speed up dev cycles without having to re-deploy anything.

With the serverless offline plugin you can speed up local dev is by emulating AWS lambda and API Gateway locally when developing your Serverless project.

  1. Install the plugin

    npm install serverless-offline --save-dev
  2. Then add the plugins key in serverless.yml

    plugins:
      - serverless-offline
  3. Now you should have the serverless offline commands available when running serverless -help

Serverless has a lot of useful plugins to test code locally before deploying to a remote environment. This helps developers save time of unnecessary deploys.

Additional emulation resources:

PS! How do you speed up your dev flow?!

Image credit

About David Wells

David Wells is a developer at Serverless, Inc.

 - 04.04.17

Python EVE + MongoDB + Serverless + AWS = REST All Happiness

Learn how to build and deploy a Serverless REST API using Python EVE and MongoDB

written by Naresh Surisetty a.k.a devilrancy

news - 03.05.18

React to any cloud event with hosted Event Gateway

Event Gateway as a hosted service, configurable connectors, and a plugin for the Serverless Framework.

written by Alex DeBrie

Join 16,000 other developers and keep up to speed on the latest serverless news and releases.

Join 16,000 other developers and keep up to speed on the latest serverless news and releases.

Made with love in San Francisco + Atlanta, Austria, Germany, Pakistan, Poland, Nebraska & Thailand

Serverless, Inc. © 2018

Join our monthly newsletter to get the latest Serverless news, updates and happenings.