• Stars
    star
    108
  • Rank 314,661 (Top 7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python module to make Flask compatible with AWS Lambda for creating RESTful applications

flask-lambda

Python module to make Flask compatible with AWS Lambda for creating RESTful applications.

Installation

pip install flask-lambda

Usage

This module works pretty much just like Flask. This allows you to run and develop this applicaiton locally just like you would in Flask. When ready deploy to Lambda, and configure the handler as:

my_python_file.app

Here is an example of what my_python_file.py would look like:

import json
from flask import request
from flask_lambda import FlaskLambda

app = FlaskLambda(__name__)


@app.route('/foo', methods=['GET', 'POST'])
def foo():
    data = {
        'form': request.form.copy(),
        'args': request.args.copy(),
        'json': request.json
    }
    return (
        json.dumps(data, indent=4, sort_keys=True),
        200,
        {'Content-Type': 'application/json'}
    )


if __name__ == '__main__':
    app.run(debug=True)

Flask-RESTful

Nothing special here, this module works without issue with Flask-RESTful as well.

API Gateway

Configure your API Gateway with a {proxy+} resource with an ANY method. Your "Method Response" should likely include an application/json "Response Body for 200" that uses the Empty model.

Deploying

Consider using python-mu.

Lambda Test Event

If you wish to use the "Test" functionality in Lambda for your function, you will need a "API Gateway AWS Proxy" event. Below is an event to test the above sample application:

{
  "body": "{\"test\":\"body\"}",
  "resource": "/{proxy+}",
  "requestContext": {
    "resourceId": "123456",
    "apiId": "1234567890",
    "resourcePath": "/{proxy+}",
    "httpMethod": "POST",
    "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
    "accountId": "123456789012",
    "identity": {
      "apiKey": null,
      "userArn": null,
      "cognitoAuthenticationType": null,
      "caller": null,
      "userAgent": "Custom User Agent String",
      "user": null,
      "cognitoIdentityPoolId": null,
      "cognitoIdentityId": null,
      "cognitoAuthenticationProvider": null,
      "sourceIp": "127.0.0.1",
      "accountId": null
    },
    "stage": "prod"
  },
  "queryStringParameters": {
    "foo": "bar"
  },
  "headers": {
    "Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
    "Accept-Language": "en-US,en;q=0.8",
    "CloudFront-Is-Desktop-Viewer": "true",
    "CloudFront-Is-SmartTV-Viewer": "false",
    "CloudFront-Is-Mobile-Viewer": "false",
    "X-Forwarded-For": "127.0.0.1, 127.0.0.2",
    "CloudFront-Viewer-Country": "US",
    "Accept": "application/json",
    "Upgrade-Insecure-Requests": "1",
    "X-Forwarded-Port": "443",
    "Host": "1234567890.execute-api.us-east-1.amazonaws.com",
    "X-Forwarded-Proto": "https",
    "X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
    "CloudFront-Is-Tablet-Viewer": "false",
    "Cache-Control": "max-age=0",
    "User-Agent": "Custom User Agent String",
    "CloudFront-Forwarded-Proto": "https",
    "Accept-Encoding": "gzip, deflate, sdch",
    "Content-Type": "application/json"
  },
  "pathParameters": {
    "proxy": "foo"
  },
  "httpMethod": "POST",
  "stageVariables": {
    "baz": "qux"
  },
  "path": "/foo"
}

To update your test event, click "Actions" -> "Configure test event".

More Repositories

1

speedtest-cli

Command line interface for testing internet bandwidth using speedtest.net
Python
12,974
star
2

ansible-template-ui

Web UI for testing ansible templates
Python
100
star
3

bonding

A script used to configure bonding on Linux machines, and to determine which interface groups (peers) are available for bonding.
Python
51
star
4

go-speedtest

An experimental Go command line interface for testing internet bandwidth using speedtest.net
Go
50
star
5

mu

Python module and CLI to package and upload python lambda functions to AWS Lambda
Python
25
star
6

github-notify

Email Notifier for GitHub Issues and Pull Requests
Python
22
star
7

ansible-training-content

Official Ansible Training Content
Python
22
star
8

bistory

Bash history search tool
Python
19
star
9

toiletwater

You might be able to drink it in an emergency, but you might still die
Python
19
star
10

powerline-shell-go

Attempted fork of powerline-shell into Go
Go
17
star
11

syncat

Command line interface similar to cat with syntax highlighting
Python
13
star
12

ansible-testing

Python module to help test or validate Ansible, specifically ansible modules
Python
11
star
13

travaul-toggle

Angular Directive to Provide Toggle Buttons
CSS
9
star
14

amanda

A simple web application, to mimic the V2 API endpoints for Ansible Galaxy Collections, with no database, just a directory with artifacts
Python
9
star
15

travis-encrypt

Go
8
star
16

ansible-playbooks

Ansible Playbooks for my personal stuff
Python
8
star
17

keyster

An SSH authorized key store for use with OpenSSH AuthorizedKeysCommand
Go
8
star
18

requisitor

Simple Python HTTP library utilizing only Python stdlib
Python
7
star
19

gohaste

Go implementation of a concurrent Rackspace CloudFiles Upload/Download/Delete application
Go
5
star
20

overseer

Simple monitoring server written in Go, similar to pingdom but with no UI
Go
4
star
21

ipython-reload

IPython magic command to reload modules on demand
Python
4
star
22

dockersshell

Login shell that spawns a docker instance and initiates an SSH connection with it
Go
4
star
23

ansible-pulp-galaxy-ng

Playbook to create a working pulp/pulp_ansible/galaxy_ng container via ansible
3
star
24

sai

A simple API utility for invoking Ansible playbooks
Python
3
star
25

raxdyndns

Dynamic DNS Updater for Rackspace Cloud DNS
Python
3
star
26

libselinux-python-wheels

POC Ansible playbooks to build wheel files for libselinux-python
Python
3
star
27

pyaxel

Multithreaded Download accelerator with resume support implemented in python
Python
3
star
28

gus

Simple webpage listing all of a persons "assigned" GitHub items. Issues/Pull Requests/Requested Reviews
JavaScript
2
star
29

docker-images

Docker Images
Dockerfile
2
star
30

scripts

Shell
2
star
31

prmove

Github Pull Request Mover, specifically for the Ansible repo consolidation
Python
2
star
32

httptester

HTTP Test container
Shell
2
star
33

go-coreutils

My playground for GNU coreutils written in Go
Go
2
star
34

pypi-cloudfiles

A setuptools wrapper script for uploading packages to Rackspace CloudFiles and building a PyPI compatible index.
Python
2
star
35

happymongo

Python module for making it easy and consistent to connect to MongoDB via PyMongo either in Flask or in a non-flask application
Python
2
star
36

rax-api-challenge

Rackspace API Challenges
Python
1
star
37

ansible-openssh

Ansible role to install and configure openssh
1
star
38

perky

Stripped down version of droopy written in Go
Go
1
star
39

tmhi

Python Library for T-Mobile Home Internet (Work in Progress)
Python
1
star
40

el5-python26-rpm

Patches for EL5 RPMs to support the python rpm and yum modules to work with EPEL installed python2.6
1
star
41

iter_tar

Python library to iterate through a tar file
Python
1
star
42

ansible-tests

Ansible playbooks and such for testing the functionality of Ansible functionality
1
star
43

ovpn2onc

Convert OPVN client files to ONC format
Python
1
star
44

ansible-collection-jinja2

Exposes updated jinja2 filters and tests via an Ansible collection
Python
1
star
45

sivel.net

sivel.net, what else?
CSS
1
star
46

barter

Docker Machine Import/Export
Python
1
star
47

python-apt-wheel

Ansible playbooks to build wheel files for python-apt
Python
1
star
48

spinclass

Demo app to spin up a specified number of OpenStack Compute instances, monitor and time their build status
Go
1
star
49

ansible-memory-profiler

Docker image to aid in memory profiling an ansible playbook using cgroups
Python
1
star