• Stars
    star
    129
  • Rank 279,216 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 9 years ago

Reviews

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

Repository Details

An experiment in static site genration using Contentful and AWS Lambda

Contentful AWS S3 and lambda static website generator

Library to generate static websites hosted on Amazon S3 using the Contentful sync API as source of the content and AWS Lambda to generate the static pages. This library also uses internally AWS Kinesis to distribute the page rendering workload.

Synopsis

Contentful is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation.

Amazon S3 is a object storage accessible using the HTTP protocol, it's designed for durability of 99.999999999% of objects.

AWS Lambda is a compute service that runs code in response to events managing automatically compute resources necessary to run the code.

AWS Kinesis is a cloud-based service for real-time processing of large, distributed data streams.

Disclaimer

This project is at proof of concept stage and is built on a best effort kind of approach without any guarantee of correctness, support or reliability.

Architecture

This project uses 2 lambda functions connected via an AWS Kinesis stream in order to render static pages from the entities fetched from the Contentful Delivery sync API.

The first lambda function manages the communication with the Contentful sync api, and writes every single entity to the AWS kinesis stream.

The second lambda function reads the entities from the kinesis stream and per each entity renders a Dot.js and saves the resulting HTML on Amazon S3.

                   +-----------------+
                   |                 |
                   |     lambda      |
                   | contentful sync |
                   |                 |
                   +--------+--------+
                            |
                            |
                            v
                   +--------+--------+
                   |                 |
                   | kinesis stream  |
                   |                 |
                   +-----------------+
                            |
                            |
                            v
                   +-----------------+
                   |     lambda      |
                   |  HTML template  |
                   |    rendering    |
                   +-----------------+
                            |
                            |
                            v
                   +-----------------+
                   |                 |
                   |   S3 storage    |
                   |                 |
                   +-----------------+

Prerequisites

To use this library is necessary to have an Amazon AWS account and configure the following elements:

  1. An S3 bucket that will be used to store the static pages and the Synchronization status.
  2. A Kinesis stream that will be used to distribute the rendering workload.
  3. An IAM role that will be used by the lambda functions. This role should have the following permissions
  4. getObject, putObject, putObjectACL on the S3 bucket
  5. PutRecords on the kinesis stream
  6. logging permission as described in the AWS HOWTO
  7. A working installation of the AWS CLI

Configuration

Create a JSON configuration file as follows with the data of the Contentful space that you want to generate static pages for and the AWS entities details. Please note that this library assumes that the source space is the cfexampleapi Contentful example space, to work with other spaces is necessary to adapt the templates in the templates directory.

{
  "aws": {
    "region": "us-west-2",
    "s3": {
      "bucket": "lambda-bucket-test"
    },
    "kinesis":{
      "streamName": "lambda-test-kinesis-stream"
    }
  },
  "contentful": {
    "accessToken": "b4c0n73n7fu1",
    "space": "cfexampleapi"
  }
}

Save the file with the name config.json in the root directory of this project.

Create another file to configure the shell wrappers filling in the appropriate AWS details

# the aws region
AWS_REGION=us-west-2
# the aws account number (used to prefix some AWS ARNs)
AWS_ACCOUNT_NUMBER=111111111111
# the name of the role that the lambda function will adopt
LAMBDA_IAM_ROLE=lambda-executor
# the name of the lambda function controlling the Contentful sync API
LAMBDA_CONTENTFUL_SYNC_NAME=contentful-sync-test
# the name of the lambda static rendering function
LAMBDA_KINESIS_RENDERING_NAME=contentful-consumer-test

Save the file with the name config.sh in the root directory of this project.

Installation

Install the npm dependencies.

npm install

Create the lambda function to handle the Contentful sync API:

./bin/upload-sync.sh

This will create a zip archive of the project, upload it on AWS Lambda and it will configure the LAMBDA_CONTENTFUL_SYNC_NAME function.

Create the lambda function to handle the Kinesis to S3 rendering:

./bin/upload-consumer.sh

This will create a zip archive of the project, upload it on AWS Lambda and it will configure the LAMBDA_KINESIS_RENDERING_NAME function.

Bind the LAMBDA_KINESIS_RENDERING_NAME function to the AWS Kinesis stream:

./bin/add_source.sh

This will instruct the lambda function to consume the Kinesis stream.

Usage

Trigger execution of the AWS Lambda Contentful sync function

./bin/exec.sh

This should generate in the configured AWS S3 bucket one HTML file per each entry or asset in the original Contentful space. The lambda functions will log in the log section of AWS CloudWatch.

License

Copyright (c) 2015 Contentful GmbH - Paolo Negri. See LICENSE.txt for further details.

More Repositories

1

Concorde

Download and decode progressive JPEGs on iOS.
Objective-C
1,441
star
2

gqli.rb

Ruby GraphQL Client for Humans
Ruby
212
star
3

kube-secret-syncer

A Kubernetes operator to sync secrets from AWS Secrets Manager
Go
197
star
4

coredns-nodecache

Nodelocal DNS implementation as a CoreDNS plugin
Go
75
star
5

terraform-diff

Always know where you need to run Terraform plan & apply!
Go
64
star
6

contentful-go

Contentful api SDK for GoLang
Go
44
star
7

contentful-metalsmith-example

Simple project to show the usage of the contentful-metalsmith plugin
HTML
32
star
8

terraform-contentful

Terraform provider for Contentful
Go
29
star
9

ui-editable-table

A UI-Extension to enrich the editor with an editable table
HTML
28
star
10

product-catalogue-web.ts

Demo application in Typescript / Angular2 to consume spaces from Contentful which implement the product catalogue template.
TypeScript
27
star
11

file-upload-example

Example application to demonstrate the new direct file upload feature of Contentful.
JavaScript
21
star
12

keepachangelog

Parse, modify, and create change logs
JavaScript
20
star
13

contentful-importer.rb

Generic Contentful importer.
Ruby
19
star
14

contentful.py

This project is unofficial and currently unsupported, the official SDK can be found here: https://github.com/contentful/contentful.py
Python
18
star
15

continous-delivery-environments-example

An example application for how you can Integrating migrations in your continous delivery pipeline.
JavaScript
18
star
16

gazette

Contentful Gazette: bidirectional real-time content management and delivery
JavaScript
16
star
17

gitify-dependencies

CLI tool for replacing node dependencies with their respective git repositories.
JavaScript
15
star
18

md-to-html-lambda

JavaScript
8
star
19

webhook-apigateway-lambda-slack.js

Demo setup of an integration of Contentful's webhooks with a slack channel.
JavaScript
8
star
20

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.
CSS
8
star
21

gatsby-starter-contentful-knowledge-base

A gatsby starter for knowledge base apps powered by Contentful.
JavaScript
7
star
22

lookbook-example

Browser app example for createing a Lookbook with Contenful https://www.contentful.com/blog/2015/09/10/creating-a-digital-lookbook/
JavaScript
7
star
23

continous-delivery-environments-tutorial-starter

Starting Repo for continous delivery pipeline tutorial. For a completed project see https://github.com/contentful-labs/continous-delivery-environments-example
Python
7
star
24

contentful-action-example

Example repo showcasing how to use Contentful Action Repo
JavaScript
6
star
25

cosmonaut

Explore the awesome depths of Spaces (to be read in Neil deGrasse Tyson's voice)
JavaScript
6
star
26

cdn-webinar-store-demo

The "Store" demo from the Content Delivery API Webinar on 2014.07.10
CSS
6
star
27

contentful-cardboard

Google Cardboard VR displaying entries from Contentful
Java
5
star
28

droidstory

Sample Android app using Vault.
Java
5
star
29

ui-country-select

A UI-Extension to enrich the editor with a country select
HTML
5
star
30

super-chemex-bot

Our friendly bot-overlord notifying people when there is freshly brewed coffee in the kitchen.
JavaScript
4
star
31

ui-reference-quick-select

A UI-Extension to enrich the editor with a reference quick select
HTML
4
star
32

contentful-algolia-integration

JavaScript
3
star
33

cma_import_script

Sample script using the contentful management api to create a space with data.
Ruby
3
star
34

spec-super-chemex-bot

Super Chemex Bot - Slack Spec Edition
JavaScript
3
star
35

contentful_mirror

Contentful Module for Magic Mirror
JavaScript
2
star
36

reposite-contentful-template

Reposite template for Contentful repositories
CSS
2
star
37

jumpgate-app

WIP - Design system app exploration
TypeScript
2
star
38

kramdown-instant-article

A Kramdown converter optimised for Facebook Instant Articles
Ruby
2
star
39

contextual-help

Content type contextual help UI extension
JavaScript
2
star
40

floating-editor-extension

JavaScript
1
star
41

Atom-Exporter

An Atom package for exporting your current workspace (or sub folder of it) into Contentful
CoffeeScript
1
star
42

scheduling_app

Scheduled publishing using Contentful's API and Middleman
Ruby
1
star
43

slack-bot-command-example

Gomix Slack Command Example
JavaScript
1
star
44

contentful_aframevr_middleman

Contentful + AFrame VR + Middleman example
Ruby
1
star
45

duplicate-space-cli

A bash script that will create a new space and duplicate the content model from your reference space.
Shell
1
star