Getting Started With Serverless, Python, and Stackery

Serverless is a new methodology for building and running web workers. If you’re familiar with Python, you have all the knowledge you need to build a scalable and modern web application. Let’s go over some basics and discover how Stackery can help.

What is Serverless?

These are five general characteristics that classify cloud services as serverless
  1. No server-management (including virtual machines or containers): the cloud provider does this for you
  2. Pricing based on consumption, not capacity: you pay for resources only when they’re in use
  3. Built-in scaling: a resource or application that scales to meet demand
  4. Automatic availability and fault-tolerance: more things you don’t have to worry about
  5. Provisioning resources through infrastructure-as-code, not hardware

Serverless starts with functions

The seed of any serverless application is a serverless function. Rather than a full web server with the code necessary to handle web requests, a serverless function (in AWS, serverless functions are called Lambdas) contains just the logic needed to handle an incoming event from an API Gateway or another source.

Remember that, on their own, serverless functions on AWS can’t even communicate with the outside world. The critical takeaway is that while serverless starts with functions you need more than functions to do anything.

A Serverless App’s Building Blocks

Serverless applications have three components:

  • Business logic: a function (AWS Lambda) that defines the logic of the application
  • Building blocks: Resources such as databases, API Gateways, authentication services, IOT, machine learning, container tasks, and other cloud services that support a function
  • Workflow phase dependencies: Environment-configuration and secrets that respectively define and enable access to the dependencies unique to each phase of the development workflow

Functions should be web workers, not serving static assets

Many early tutorials start with serving a simple HTML response by hooking an API Endpoint to a serverless function (AWS Lambda). This is an okay way to start learning but in general serverless functions should be doing work not serving static assets.

Building your Python Lambdas

Python is an ideal language for writing serverless: high-level languages reduce dev time and lets you focus on business logic.

Get the tools you need

The software needed is all freely available and all you’ll need is an AWS and a Stackery account

Build your first serverless app in nine minutes

Watch our quickstart video to see how!

The Lazy Programmer’s Guide to Web Scrapers

Once you’ve built your first few Lambdas, it’s time to actually do some work with your them. Check out our guide to building a web scraper in Python.

Debugging the Lambdas you’ve deployed

If you’ve already built your Lambdas, you know that most of the challenges of serverless come not with building Lambdas but with maintenance and management. Serverless means not worrying about OS updates or detailed server management, but when you need to test new code, things can get tricky.

The first and most significant hurdle is having to deploy to AWS every time you have new Lambda code you want to test. When you’re waiting five minutes to test a single new line of code, development can slow to a crawl.

You think you want local development-
what you really want is cloudlocal development

AWS, well aware that people don’t want to wait 5 minutes to test their code, has released the SAM CLI to let you test your Lambdas locally. It is a great tool with some severe limitations.

  • While a local Docker container can emulate Lambdas and API Gateways for your Lambda, it cannot emulate other services like SQS or Fargate
  • Even if you could locally emulate DB tables from services like DynamoDB, you, of course, could not emulate a DB state, and there’s no way to store something like a local DB state for testing
  • Since Lambdas are stateless, there’s no way to emulate any of the work that Lambdas should be tasked with, since there’s no place to save any state!

Get cloudlocal with local Python development and managed cloud resources with the Stackery CLI and a free Stackery account

So how do you debug things like a DB request from a Lambda? Enter the Stackery CLI. It lets you run your Lambdas locally, while still sending requests out to resources in the AWS Cloud

  1. Plan your app with the Stackery editor
  2. Deploy using CloudFormation
  3. Re-write your Lambda code
  4. Execute that code locally, with the Lambda still able to make a request to your cloud-side DB, Fargate, and others.

Try the Stackery CLI today to see it in action!

Develop on Serverless with Confidence

Experience cloudside development with Stackery – select and configure services, develop Lambdas locally against live AWS services and manage your serverless apps from pipeline to production.

To Top