Example application showing how to build an entirely serverless site with Python, Flask, and Contentful. Then seamlessly deploy it to AWS Lambda/API Gateway using Zappa. Live example sitting at https://henshin.ruparel.co/.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
import_export
static/css
templates
.gitignore
LICENSE
README.md
app.py
requirements.txt
zappa_settings.json

README.md

zappa-contentful

Example application showing how to build an entirely serverless site with Python, Flask and Contentful. Then seamlessly deploy it to AWS Lambda/API Gateway using Zappa. A live version of this site lives at henshin.ruparel.co.

Requirements

To use this project you have to have a Contentful and AWS account. If you don't have a Contentful account yet, you can register at www.contentful.com/sign-up.

Getting started

Before you begin, make sure you are running Python 3.6.

Get the source code and install dependencies.

$ git clone git@github.com:contentful-labs/zappa-contentful.git
$ cd zappa-contentful
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt

You can use python app.py to run the application locally.

Set up the content model and update the API Keys.

This project comes pre-connected to a live Contentful space. For you to be able to modify and evolve the project, you'll need to create your own Contentful space.

From the Contentful website click on the name of the space in the top left corner of the interface and select 'Add new Space'. Select the blank space option. Name your space, select its default locale (language) and the organization it should belong to. Then hit 'Create Space'.

To import the content model into your new space you'll need to install the Contentful import tool.

npm install -g contentful-import

Once that's installed you'll be able to import the content model into your new space using the following command:

contentful-import \
  --space-id spaceID \
  --management-token managementToken \
  --content-file import_export/export.json

Make sure to update the command with your spaceID and mangementToken. You're able to find both of those keys via app.contentful.com -> Space Settings -> API keys.

Once that's taken care of update your app.py file with your new SPACE_ID and DELIVERY_API_KEY.

Running Locally and deploying to AWS Lambda

To run the project locally, you can use python app.py.

Zappa handles most of the legwork required to deploy on Lambda. Make sure that you've already installed and configured the AWS CLI.

To deploy to the cloud you can either use the existing Zappa configuration file or let Zappa automatically configure your deployment settings with zappa init.

If you use the configuration file in this repo you can deploy both a dev and production environment. For your dev environment use zappa deploy dev and for production zappa deploy production. The zappa deploy command will return a URL where you can access your website.

Once you've deployed your dev and production environment if you make a code change you can use zappa update dev or zappa update production to push your code change to lambda without resulting in a chance to the URL that your function is deployed on.

If you head over to API Gateway, you'll see a new API containing your function.

From this point, it's also possible to set up a custom domain and SSL certificate.