You are currently viewing Serverless Framework (Windows) – How to Deploy Python REST API to AWS

Serverless Framework (Windows) – How to Deploy Python REST API to AWS

  • Post category:AWS
  • Post comments:0 Comments

In this walk-through, we will:

  • Install Serverless Framework (Windows)
  • Deploy a Python REST API endpoint

Getting Started

To get started, you’ll need the Serverless Framework installed. You’ll also need your environment configured with AWS credentials.

Install as a standalone binary Serverless Framework (Windows)

Install with Chocolatey:

choco install serverless

For other operating systems , please visit the link.

Create a new directory

Let’s start by deploying a single endpoint.

First, create a new directory with a package.json file

mkdir hello-world && cd hello-world
npm init -f

Then, install a few dependencies. We’re going to use the serverless-wsgi plugin for negotiating the API Gateway event type into the WSGI format. We’ll also use the serverless-python-requirements plugin for handling our Python packages on deployment.

npm install --save-dev serverless-wsgi serverless-python-requirements

Create an IAM User and Access Key

The Serverless Framework (Windows) needs access to AWS account so that it can create and manage resources. Follow these steps to create an IAM user for the Serverless Framework (Windows):

  1. Login to your AWS account and go to the Identity & Access Management (IAM) page.
  2. Click on Users and then Add user. Enter a name in the first field to remind you this User is related to the Service you are deploying with the Serverless Framework (Windows), like serverless-servicename-agent. Enable Programmatic access by clicking the checkbox. Click Next to go through to the Permissions page. Click on Create policy. Select the JSON tab, and add a JSON file.
    "Statement": [
            "Action": [
            "Effect": "Allow",
            "Resource": "*"
    "Version": "2012-10-17"

Check to make sure everything looks good and click Create user. View and copy the API Key & Secret to a temporary place. You can export them as environment variables, so they would be accessible to Serverless and the AWS SDK in your shell:

set AWS_ACCESS_KEY_ID=<your-key-here>
set AWS_SECRET_ACCESS_KEY=<your-secret-key-here>
# AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are now available for serverless to use

# 'set' command is valid only for Windows. In Unix - use 'export' instead of 'set'

Deploy Hello World using Serverless Framework (Windows)

AWS – Create

Creates a new service in the current working directory based on the provided template.

serverless create --template aws-python3 --name hello-service
import json

def hello(event, context):
    body = {
        "message": "Go Serverless v1.0! Your hello-world function executed successfully!",
        "input": event

    response = {
        "statusCode": 200,
        "body": json.dumps(body)

    return response
# Welcome to Serverless!
# This file is the main config file for your service.

service: hello-service # NOTE: update this with your service name
  name: aws
  runtime: python3.8
  stage: dev
  region: us-east-1

# you can add packaging information here
#  include:
#    -
#    - include-me-dir/**
    - .vscode/**

    handler: handler.hello
    memorySize: 128
    timeout: 30 

#    The following are a few example events you can configure
#    NOTE: Please make sure to change your handler code to work with those events
#    Check the event documentation for details
      - http:
          path: hello-path
          method: get

Deploy the app
serverless deploy

Delete Endpoint

serverless remove

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.