Implementing Fauna as infrastructure as code with Serverless Framework
This post refers to a previous version of FQL.
This post refers to a previous version of FQL (v4). For the most current version of the language, visit our FQL documentation.
Benefits of IaC
- Decreased risks: Provisioning all of your infrastructures manually can be risky, especially if you have multiple dependencies among services. Complex deployment is prone to human errors. When you automate the process with IaC, you reduce these. Your infrastructure also becomes testable, and you can spin up multiple environments (exact replicas of production).
- Efficient software development lifecycle: With IaC, infrastructure provisioning becomes more reliable and consistent. Developers get complete control of the infrastructure through code. Developers can script once and use that code multiple times, saving time and effort while keeping full control.
- Self-documenting and reduced administration: IaC is self-documenting. And it reduces administrative overhead, allowing your engineering efforts to be focused on new feature development.
Getting started with the Fauna Serverless Framework plugin
$ npm install @fauna-labs/serverless-fauna --save-dev
$ yarn add @fauna-labs/serverless-fauna
serverless.yml
file and add the following code to add Fauna to your project.plugins:
- "@fauna-labs/serverless-fauna"
fauna:
client:
secret: ${env:FAUNA_ROOT_KEY}
# domain: db.fauna.com
# port: 433
# scheme: https
[db.fauna.com](http://db.fauna.com)
. You can create new collections by adding the collection name under the collections
field as demonstrated in the following code. fauna:
client:
secret: ${env:FAUNA_ROOT_KEY}
# domain: db.fauna.com
# port: 433
# scheme: https
collections:
Movies:
name: Movies
data:
some_data_key: some_data_value
fauna:
client:
secret: ${env:FAUNA_ROOT_KEY}
# domain: db.fauna.com
# port: 433
# scheme: https
collections:
Movies:
name: Movies
data:
some_data_key: some_data_value
functions:
double:
name: double
body: ${file(./double.fql)}
indexes:
movies_by_type:
name: movies_by_type
source: ${self:fauna.collections.Movies.name}
terms:
fields:
- data.type
Building a REST API with AWS Lambda, Fauna, and Serverless Framework
This tutorial teaches you how to build a serverless REST API using AWS Lambda and Fauna (as your database). You use the Serverless Framework as your infrastructure as code for this tutorial. Create a new serverless project by running the following command to get started.
Fauna AWS Workshop ~ Building an event-driven app with AWS services and Fauna
This hands-on guide walks you through building a real-world event-driven serverless application using AWS services (i.e., AWS Lambda, Step Functions, API Gateway) and Fauna. In this workshop, you build a vacation booking application (Similar to Kayak or Redtag deals).
If you enjoyed our blog, and want to work on systems and challenges related to globally distributed systems, and serverless databases, Fauna is hiring
Subscribe to Fauna's newsletter
Get latest blog posts, development tips & tricks, and latest learning material delivered right to your inbox.