This is a starter-kit for using the Fauna JavaScript Driver on Compute@Edge.
For more details about this and other starter kits for Compute@Edge, see the Fastly Developer Hub.
This starter kit provides the necessary dependencies and configuration allowing you to immediately write queries that
store and retrieve data from Fauna. It is also a sample for building REST APIs with Compute@Edge.
The sample simply implements a GET /
endpoint, providing an example of sending query requests to Fauna.
In this contrived example, the query simply asks the database to concatenate the words "Hello" and "World",
returning the string "Hello World" as a response, but you should be able to send any query to the database.
Follow these
instructions to create a database and get a database access token. For local development,
copy and paste the value of the database access token into FAUNA_ACCESS_KEY
in the fastly.toml file.
fastly compute serve
Deploy using Fastly CLI
-
Deploy
fastly compute publish --status-check-off
When prompted, provide the following values:
- Create a new service:
y
- Service name: Provide name or use defaulted value
- Domain: Provide domain name or use dafaulted value
- Backend (hostname or IP address, or leave blank to stop adding backends):
db.fauna.com
- Backend port number:
443
- Backend name:
fauna
- Create a new service:
-
Create a private dictionary using the web interface, API or fastly CLI:
- Dictionary name =
fauna_env_variables
- Set write-only =
true
- Create a dictionary item with the key =
FAUNA_ACCESS_KEY
and value = the database access token obtained from the Fauna database.
Example steps using CLI:
- Create dictionary
fastly dictionary create \ --version=active --autoclone --write-only \ --name=fauna_env_variables
- Get the dictionary Id
fastly dictionary list --version=latest
- Enter the key-value pair
fastly dictionary-entry update \ --dictionary-id=DICTIONARY-ID \ --key=FAUNA_ACCESS_KEY \ --value=<ACCESS_KEY>
- Dictionary name =
-
Activate the service
fastly service-version activate --version=latest
-
Monitor logs
fastly log-tail
Please see CONTRIBUTING.
Fauna is a distributed document-relational database delivered as a cloud API. It combines support for semi-structured data with powerful relational features such as foreign keys, views, and joins. It's native serverless architecture means having to worry less about operations, and is well suited to building edge applications using Fastly's Compute@Edge.