Samples
Angular & Node.js
This sample demonstrates how to deploy a full-stack Angular and Node.js application with Defang. It uses Socket.IO for real-time communication. The Docker setup ensures the app can be easily built and deployed.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
- Install Node.js
- Install Angular CLI
Development
For development, we use two local containers, one for the frontend Angular service and one for the backend service in Express. It also uses Caddy as a web server for serving static files.
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Angular & Node.js
Short Description: A full-stack application using Angular for the frontend and Node.js with Socket.IO for the backend, containerized with Docker.
Tags: Angular, Node.js, Socket.IO, TypeScript, JavaScript
Languages: nodejs
Arduino Flask Wifi Server
This sample contains an interactive wifi-connected UI program for a SenseCAP Indicator Device, built for an Embedded Systems project at Defang Software Labs.
The device has a square liquid-crystal touch screen display, and a ESP32-S3 chip that can be programmed in an Arduino environment.
The program welcome.ino
, acting as a client, pings data every 5 seconds after it is connected to a wifi network. It uses a library called ArduinoHTTPClient. It is also recommended to use Arduino IDE when coding with .ino
files. The program UI will display a message that is randomized in color and location on the screen at the same time during pings (every 5 seconds).
The Flask server in web_server.py
receives these pings when it is initialized and connected to the same wifi network as the client. To initalize it, run python web_server.py
. To view it, open localhost
with the port number used. To deploy it to the cloud, run defang up
in the \welcome
directory.
A helpful file called serial_reader.py
decodes serial monitor readings to a readable format, allowing you to see Serial.println()
messages in real time when running. To initalize it, run python serial_reader.py
and see it show up in the terminal.
Here is a diagram showing the structure of the application.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Arduino Flask Wifi Server
Short Description: An Arduino wifi server built with Flask.
Tags: Arduino, Flask, Python, IoT, Wifi, Serial
Languages: python
BullMQ & BullBoard & Redis
This sample demonstrates how to deploy a BullMQ message queue on top of managed Redis with a queue processor and a dashboard to monitor the queue.
Once your app is up and running you can go to the /board
route for the board
service to see the Bull Board dashboard and use the username admin
and the board password you set to log in (see Configuration).
To add a job to the queue, you can go to the /add
route of the api
service. This will use some default values so you can test things out. You can also see an example of a post request in the sample HTTP request file.
The worker
service is the queue processor that will process the jobs added to the queue. You can see in the compose.yaml
file that the worker
service is set to scale to 2 instances. This means that there will be 2 workers processing jobs from the queue. You can set this to your desired number of workers, but we wanted to show how you can increase the number of workers to handle more jobs.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
BOARD_PASSWORD
Set a board password and use together with the board username admin
when signing in.
defang config set BOARD_PASSWORD
QUEUE
defang config set QUEUE
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: BullMQ & BullBoard & Redis
Short Description: A sample project with BullMQ, BullBoard, and Redis.
Tags: BullMQ, BullBoard, Redis, Express, Node.js, Message Queue, JavaScript
Languages: nodejs
Crew.ai Django Sample
This sample shows how to use Crew.ai with a Django application. It provides a simple web interface that allows users to input text and receive a summary of the text in real-time using Django Channels with a Redis broker. It uses Celery to handle the Crew.ai tasks in the background with Redis as a broker. It uses Postgres as the database for Django.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f ./compose.local.yaml up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
The password for the Postgres database.
defang config set POSTGRES_PASSWORD
SSL_MODE
The SSL mode for the Postgres database.
defang config set SSL_MODE
DJANGO_SECRET_KEY
The secret key for the Django application.
defang config set DJANGO_SECRET_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Crew.ai Django Sample
Short Description: A sample application that uses Crew.ai to summarize text in a background task, streamed to the user in real-time.
Tags: Django, Celery, Redis, Postgres, AI, ML
Languages: Python
C# & ASP.NET Core
This sample project is a simple task manager application using ASP.NET Core for the backend and JavaScript for client-side component rendering.
It showcases how you could deploy a full-stack application with ASP.NET Core and JavaScript using Defang. The Docker setup ensures the app can be easily built and tested during development.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
- Install ASP.NET Core
Development
For development, we use two local containers, one for the frontend service and one for the backend service in ASP.NET Core. It also uses Caddy as a web server for serving static files.
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: C# & ASP.NET Core
Short Description: A simple task manager application using C# and ASP.NET Core.
Tags: ASP.NET Core, JavaScript, C#
Languages: C#
Django
This sample is a simple Django to-do app that uses SQLite as the database, which will be reset every time you deploy. It is not production-ready. For production use cases, you should check out the Django + Postgres sample.
The app includes a management command which is run on startup to create a superuser with the username admin
and password admin
. This means you can login to the admin interface at /admin/
and see the Django admin interface without any additional steps. The example_app
is already registered and the Todo
model is already set up to be managed in the admin interface.
The Dockerfile and compose files are already set up for you and are ready to be deployed. Serving is done using Gunicorn and uses WhiteNoise for static files. The CSRF_TRUSTED_ORIGINS
setting is configured to allow the app to run on a defang.dev
subdomain.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Make sure to update the
CSRF_TRUSTED_ORIGINS
setting in thesettings.py
file to include an appropriate domain. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Django
Short Description: A simple Django app that uses SQLite as the database.
Tags: Django, SQLite, Python
Languages: python
Django Celery
This is a sample Django application that uses Celery for background tasks. It uses Postgres as the database and Redis as the message broker.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
The password for the Postgres database.
defang config set POSTGRES_PASSWORD
SECRET_KEY
The secret key for the Django application.
defang config set SECRET_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Django Celery
Short Description: A Django application that uses Celery for background tasks, Postgres as the database, and Redis as the message broker.
Tags: Django, Celery, Postgres, Redis
Languages: python, sql
Django Channels & Redis & Postgres
This sample demonstrates how to get Django Channels up and running with Redis and Postgres both managed by Defang. It demonstrates how to do this with a simple chat application.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up
This will start the Django server, Redis, and Postgres and mounts your Django app so you get live reloading. You can access the Django server at http://localhost:8000
.
Configuration
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
SECRET_KEY
The secret key for your Django application. You can generate a new one by running python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
. A default, insecure key is used if this is not set, but you should set it for a production deployment.
POSTGRES_PASSWORD
The password for your Postgres database. You need to set this before deploying for the first time.
Deploying
- Open the terminal and type
defang login
- Use the
defang config
command to setup environment variables. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Django Channels & Redis & Postgres
Short Description: A basic configuration of Django Channels with Redis and Postgres demonstrating a simple chat application.
Tags: Django, Channels, Redis, Postgres, Chat, Application
Languages: Python
Django & Postgres
This template is a customer relationship management list project developed using Python Django framework, offering a starting point to help you quickly build your customer management system. We use PostgreSQL as the database. We have prepared all the essential files for deployment. By spending less than 10 minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live to the world!
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
The password for the PostgreSQL database.
defang config set POSTGRES_PASSWORD
SECRET_KEY
The secret key is used to secure the Django application.
defang config set SECRET_KEY
ALLOWED_HOSTS
The allowed hosts for the Django application. (i.e. the domain your app runs on)
defang config set ALLOWED_HOSTS
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Django & PostgreSQL
Short Description: A customer relationship management list project developed using the Python Django framework, offering a starting point to help you quickly build your customer management system.
Tags: Django, PostgreSQL, Python, SQL
Languages: python
Django-Railpack
This sample is a simple Django to-do app that uses SQLite as the database, which will be reset every time you deploy. It is not production-ready. For production use cases, you should check out the Django + Postgres sample.
The app includes a management command which is run on startup to create a superuser with the username admin
and password admin
. This means you can login to the admin interface at /admin/
and see the Django admin interface without any additional steps. The example_app
is already registered and the Todo
model is already set up to be managed in the admin interface.
The compose files are already set up for you and are ready to be deployed and the image is built by Railpack. Serving is done using Gunicorn and uses WhiteNoise for static files. The CSRF_TRUSTED_ORIGINS
setting is configured to allow the app to run on a defang.dev
subdomain.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Make sure to update the
CSRF_TRUSTED_ORIGINS
setting in thesettings.py
file to include an appropriate domain. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Django
Short Description: A simple Django app that uses SQLite as the database.
Tags: Django, SQLite, Python, Railpack
Languages: python
Elysia & Bun
A basic Elysia app running on Bun with a Dockerfile and compose.yaml ready to deploy to AWS with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Elysia & Bun
Short Description: A basic Elysia app running on Bun with Defang.
Tags: Bun, Elysia, TypeScript, JavaScript
Languages: nodejs
FastAPI
This sample project demonstrates how to deploy FastAPI with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.yaml -f compose.dev.yaml up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: FastAPI
Short Description: A sample project demonstrating how to deploy FastAPI with Defang.
Tags: FastAPI, OpenAPI, Python
Languages: python
FastAPI & PostgreSQL
This sample project demonstrates how to deploy FastAPI with PostgreSQL with Defang.
Prerequisites
- Download Defang CLI
- (optional) If you are using Defang BYOC, make sure you have properly authenticated your AWS account.
Development
To run the development container(s) locally, do:
docker compose -f compose.dev.yaml up --build
Or to run the production container(s) locally, do:
POSTGRES_PASSWORD=postgres docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
defang config set POSTGRES_PASSWORD
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: FastAPI & PostgreSQL
Short Description: A sample project with FastAPI and PostgreSQL.
Tags: FastAPI, PostgreSQL, Python, SQL
Languages: python
Feathers.js
This sample project demonstrates how to deploy a FeathersJS application on to AWS using Defang. We also demonstrate how to run the application in both development and production environments using Docker Compose.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
- (Optional - for local development) Node.js
Development
For development, we use Docker to containerize the FeathersJS application. The Docker Compose configuration is defined in the compose.dev.yaml
file.
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Feathers.js
Short Description: A sample project demonstrating how to deploy a Feathers.js application using Defang. The application displays "DefangxFeathersjs" on the webpage.
Tags: Feathers.js, Node.js, JavaScript
Languages: nodejs
Flask
This is a basic Flask to-do app that can be deployed with Defang. Note that alongside your .py
file, include a requirements.txt
so that the Dockerfile can install the necessary packages with pip.
This project is intended to provide a basic understanding of how to get started with Flask on Defang. The items are stored in memory and are lost when the server is restarted. It is not intended for production use. If you need something production ready, you should use a managed database like Postgres or MySQL.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Flask
Short Description: A basic Flask to-do app.
Tags: Flask, Python
Languages: python
Flask-Railpack
This is a basic Flask to-do app that can be deployed with Defang. Note that alongside your .py
file, include a requirements.txt
so that the Railpack can install the necessary packages with pip.
This project is intended to provide a basic understanding of how to get started with Flask on Defang. The items are stored in memory and are lost when the server is restarted. It is not intended for production use. If you need something production ready, you should use a managed database like Postgres or MySQL.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Flask
Short Description: A basic Flask to-do app.
Tags: Flask, Python, Railpack
Languages: python
Go HTTP Server
A very simple example of a Go service that listens on a port and returns information about the request.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go HTTP Server
Short Description: A simple Go application that echoes back the request.
Tags: Go, HTTP
Languages: golang
Go HTTP Form
This Go application demonstrates a simple form submission using the standard net/http library. Users can input their first name into a form, and upon submission, they will be greeted personally by the application.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go HTTP Form
Short Description: A simple Go application that demonstrates form submission using the net/http library.
Tags: Go, HTTP
Languages: golang
Golang-Http-Form-Railpack
This Go application demonstrates a simple form submission using the standard net/http library. Users can input their first name into a form, and upon submission, they will be greeted personally by the application.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go HTTP Form
Short Description: A simple Go application that demonstrates form submission using the net/http library.
Tags: Go, HTTP, Railpack
Languages: golang
Go & MongoDB
This sample is a task manager application that uses Go and MongoDB, deployed with Defang.
HTML and JavaScript are used for the frontend to interact with the backend via API calls. There is a go.mod
file that includes dependencies for the Dockerfile to install.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
MONGO_INITDB_ROOT_USERNAME
The username for the MongoDB database.
defang config set MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD
The password for the MongoDB database.
defang config set MONGO_INITDB_ROOT_PASSWORD
Using MongoDB Atlas
If you want to use MongoDB Atlas, you can set the URI with defang config set MONGO_URI
and remove the value from the MONGO_URI
environment variable so that it is read from defang config. For example, in your compose.yaml
file:
services:
app:
environment:
- MONGO_URI # empty values are read from defang config
Using DocumentDB in AWS
If you want to use DocumentDB in AWS, you can add the x-defang-mongodb
extension to your compose.yaml
file:
services:
db:
x-defang-mongodb: true
This will automatically provision a DocumentDB cluster in your AWS account.
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go & MongoDB
Short Description: A simple Go application that manages tasks with MongoDB.
Tags: Go, MongoDB, Atlas, Task Manager
Languages: golang
Golang & OpenAI
This sample demonstrates how to deploy a Go project with OpenAI using Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
OPENAI_KEY
An API key to access the OpenAI API.
defang config set --name OPENAI_KEY
Testing
Below are some useful commands for testing.
echo "Hello" | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
or alternatively,
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go & OpenAI
Short Description: A simple Go application that interacts with the OpenAI API.
Tags: Go, OpenAI, ChatGPT
Languages: golang
Go & REST API
This sample shows a Go HTTP server that uses a REST API to fetch data, deployed using Defang.
It serves two endpoints: /
and /rates
. The /
endpoint responds with a JSON object containing the status, while the /rates
endpoint fetches data from the Fiscal Data Treasury API and returns the response to the client.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go & REST API
Short Description: A simple Go application that fetches fiscal data from an API.
Tags: Go, HTTP, Fiscal Data, REST API
Languages: golang
Go & S3
This sample shows a simple Go application that uploads and downloads files from AWS S3, deployed with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
AWS_ACCESS_KEY
An AWS access key to use S3.
defang config set --name AWS_ACCESS_KEY
AWS_SECRET_KEY
An AWS secret key to use S3.
defang config set --name AWS_SECRET_KEY
Testing
Below is a useful command for testing.
curl -X POST -H 'Content-Type: application/json' -d '{ "first_name" : "jane", "last_name" : "doe" }' https://xxxxxx/upload
curl https://xxxxxx/download
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Go & S3
Short Description: A simple Go application that uploads and downloads files from AWS S3.
Tags: Go, S3, AWS
Languages: golang
Go & Slack API
This is a simple Slackbot that takes a request and posts the message from the body to a Slack channel.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Slack API Token
You'll need to head to https://api.slack.com/apps to create a Slack App.
Make sure to:
- Give it the bot
chat:write
scope - Install the app to your workspace
- Copy the Bot User OAuth Access Token
- Invite your bot to the channel you want it to post to using the
@botname
command in the channel (this will allow you to invite it)
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
SLACK_TOKEN
This is the token you've copied previously for the Slack API.
defang config set SLACK_TOKEN
SLACK_CHANNEL_ID
This is the ID of the Slack channel where the bot will post messages.
defang config set SLACK_CHANNEL_ID
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Usage
Once the Slackbot is deployed, you can send a POST request to the /
endpoint with a JSON body containing the message you want to post to the Slack channel. Here's an example:
curl 'https://raphaeltm-bot--8080.prod1.defang.dev/' \
-H 'content-type: application/json' \
--data-raw $'{"message":"This is your bot speaking. We\'ll be landing in 10 minutes. Please fasten your seatbelts."}'
Title: Go & Slack API
Short Description: A simple Slackbot that posts messages to a Slack channel.
Tags: Go, Slack, Bot
Languages: golang
Hasura & PostgreSQL
This sample project demonstrates how to deploy Hasura with Defang and connect it to a Postgres database. We also demonstrate how to run a Postgres container during development and how to switch over to a managed postgres service like RDS, Neon, or others in production. If you want to get a compatible database ready to go really quickly for free, Neon is a quick and easy way to go. The sample populates the database with some sample data so you can quickly start playing with the Hasura console. It sets wide open permissions on the tables as well so you can start querying or mutating the data right away.
Prerequisites
- Download Defang CLI
- Have a managed database service configured and have the connection string ready.
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
- (Optional) Install the Hasura CLI to create migrations and update metadata for your Hasura GraphQL api.
Development
For development, we use a Postgres container. The Postgres container is defined in the compose.dev.yaml
file. The Hasura container is defined in the compose.yaml
file, with some overrides in the compose.dev.yaml
file so it can correctly connect to the development database container.
To start the development environment, run docker compose -f ./compose.yaml -f ./compose.dev.yaml up
. This will start the Postgres container and the Hasura container. The Hasura console will be available at http://localhost:8080
with the password password
.
Note: If you want to make changes to your database, permissions, etc. you should use the Hasura console and the Hasura CLI to make those changes. See the next section for more information.
Editing the database/permissions etc.
If you want to edit the database, permissions, or any other Hasura settings such that you can deploy them to production, you should install the Hasura CLI. Then, after starting the development environment, you can run hasura console
inside the ./hasura
directory. This will open the Hasura console in your browser. Any changes you make in the console will be saved to the migrations
and metadata
directories. When you run defang compose up
these changes will be applied to the production environment.
Deploying
- Open the terminal and type
defang login
- Add your connection string as a defang config value by typing
defang config set HASURA_GRAPHQL_DATABASE_URL
and pasting your connection string (which should be in the formatpostgres://username:password@host:port/dbname
) - Setup a password for hasura by typing
defang config set HASURA_GRAPHQL_ADMIN_SECRET
and adding a password you would like to login with. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Hasura & PostgreSQL
Short Description: A sample project demonstrating how to deploy Hasura with Defang and connect it to a PostgreSQL database.
Tags: Hasura, GraphQL, PostgreSQL, Database
Languages: SQL, GraphQL
HTML & CSS & JavaScript
This sample shows how to get a static HTML, CSS and JavaScript website up and running with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: HTML & CSS & JavaScript
Short Description: A simple HTML, CSS and JavaScript website running on Defang.
Tags: HTML, CSS, JavaScript, Frontend
Languages: nodejs
Huginn
This sample shows how to deploy Huginn with Defang.
Huginn is a system for building agents that perform automated tasks for you online. Huginn's Agents can monitor the web, respond to events, and act on your behalf. They propagate events along a directed graph. It's like a customizable IFTTT or Zapier on your own server, ensuring data privacy.
Prerequisites
- Download Defang CLI
- Have a managed database service configured and ready, such as Neon PostgreSQL
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f ./compose.yaml -f ./compose.dev.yaml up
This will start the Postgres container and the Huginn container. Huginn will be available at http://localhost:3000
with the username admin
and password password
.
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
DATABASE_NAME
The name of the database.
defang config set DATABASE_NAME
DATABASE_USERNAME
The username used with the database.
defang config set DATABASE_USERNAME
DATABASE_PASSWORD
The password used with the database.
defang config set DATABASE_PASSWORD
DATABASE_HOST
The host of the database.
defang config set DATABASE_HOST
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Huginn
Short Description: A system for building agents that perform automated tasks for you online.
Tags: Huginn, Agents, Automation
Languages: Dockerfile
ImgProxy
This sample shows how to deploy ImgProxy with Defang. ImgProxy is a fast and secure standalone server for resizing and converting remote images. It can be deployed using the official Docker image, as documented here.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: ImgProxy
Short Description: A fast and secure standalone server for resizing and converting remote images
Tags: Imgproxy, Images, Server
Languages: N/A
Javalin Sample
This sample demonstrates how to deploy a very basic Javalin sample with Defang. The sample simply outputs "Defang x Javalin" on the webpage.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
Deploying
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Development
For development, we use a local container. This can be seen in the compose.yaml file. To run the sample locally use the following command:
docker compose up --build
Title: Javalin
Short Description: A short hello world application demonstrating how to deploy Javalin onto Defang.
Tags: Javalin, Java, Maven
Languages: java
Langchain & Flask
This sample is an endpoint that tells programming jokes and shows how to deploy a flask app that uses Langchain on to AWS via Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
Deploying
- Open the terminal and type
defang login
- Set the environment variable
OPENAI_KEY
by typingdefang config set OPENAI_KEY
. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Development
For development, first clone the project and navigate to its directory. After such, please run the command
docker compose up --build
This will start a Docker container with the flask app which will display the result of the langchain prompt.
Title: LangChain & Flask
Short Description: A sample project demonstrating how to deploy LangChain with Flask on Defang.
Tags: LangChain, Flask, AI, Python
Languages: python
Managed LLM
This sample application demonstrates the use of OpenAI-compatible Managed LLMs (Large Language Models) with Defang.
Note: Using Docker Model Provider? See our Managed LLM with Docker Model Provider sample.
Using the Defang OpenAI Access Gateway, the feature x-defang-llm: true
enables you to use Managed LLMs on the Defang Playground or on platforms offered by BYOC providers (such as AWS Bedrock or GCP Vertex AI) with an OpenAI-compatible SDK.
This allows switching from OpenAI to the Managed LLMs on supported cloud platforms without modifying your application code.
You can configure the LLM_MODEL
and LLM_URL
for the LLM separately for local development and production environments.
- The
LLM_MODEL
is the LLM Model ID you are using. - The
LLM_URL
is the bridge that provides authenticated access to the LLM model.
Ensure you have enabled model access for the model you intend to use. To do this, you can check your AWS Bedrock model access or GCP Vertex AI model access.
To learn about available LLM models in Defang, please see our Model Mapping documentation.
For more about Managed LLMs in Defang, please see our Managed LLMs documentation.
Defang OpenAI Access Gateway
In the compose.yaml
file, the llm
service is used to route requests to the LLM API model. This is known as the Defang OpenAI Access Gateway.
The x-defang-llm
property on the llm
service must be set to true
in order to use the OpenAI Access Gateway when deploying with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.local.yaml up --build
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Managed LLM
Short Description: An app using Managed LLMs with Defang's OpenAI Access Gateway.
Tags: LLM, OpenAI, Python, Bedrock, Vertex
Languages: Python
Managed LLM with Docker Model Provider
This sample application demonstrates using Managed LLMs with a Docker Model Provider, deployed with Defang.
Note: This version uses a Docker Model Provider for managing LLMs. For the version with Defang's OpenAI Access Gateway, please see our Managed LLM Sample instead.
The Docker Model Provider allows users to run LLMs locally using docker compose
. It is a service with provider:
in the compose.yaml
file.
Defang will transparently fixup your project to use AWS Bedrock or Google Cloud Vertex AI models during deployment.
You can configure the LLM_MODEL
and LLM_URL
for the LLM separately for local development and production environments.
- The
LLM_MODEL
is the LLM Model ID you are using. - The
LLM_URL
will be set by Docker and during deployment Defang will provide authenticated access to the LLM model in the cloud.
Ensure you have enabled model access for the model you intend to use. To do this, you can check your AWS Bedrock model access or GCP Vertex AI model access.
To learn about available LLM models in Defang, please see our Model Mapping documentation.
For more about Managed LLMs in Defang, please see our Managed LLMs documentation.
Docker Model Provider
In the compose.yaml
file, the llm
service will route requests to the LLM API model using a Docker Model Provider.
The x-defang-llm
property on the llm
service must be set to true
in order to use the Docker Model Provider when deploying with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.local.yaml up --build
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Managed LLM with Docker Model Provider
Short Description: An app using Managed LLMs with a Docker Model Provider, deployed with Defang.
Tags: LLM, Python, Bedrock, Vertex, Docker Model Provider
Languages: Python
MCP
This is a sample of a Model Context Protocol (MCP) chatbot application built with Next.js, Python, and Anthropic Claude, deployed using Defang.
This example uses Docker's mcp/time
image as a base for the MCP Server (with MCP tools included), but it can be adapted to use any of the Docker MCP images.
How It Works
Service 1 (Web Server with UI)
The web server and UI are built in Next.js (see /service-1/src/app
). The web server includes a forwarding action to connect to the MCP Client.
Service 2 (MCP Client and MCP Server)
The MCP Client is written in Python and ran in a venv
virtual environment. The MCP server is provided by the Docker mcp/time
image. The MCP Server communicates with the MCP Client in a Quart app (i.e. Asynchronous Server Gateway Interface (ASGI) version of Flask) through the stdio
transport method, as seen in /service-2/main.py
. For more on MCP transport methods, see here.
Here's a breakdown of what happens when a user interacts with the UI:
- When a user submits a query to the chatbot, the browser sends a request to the Next.js web server.
- The Next.js web server will forward this request to the MCP Client via a REST endpoint.
- The MCP Client processes the request by interacting with the Anthropic (Claude) API and tools available through the MCP Server.
- Once the response is generated, it is sent back to the Next.js web server and displayed to the user in the UI.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
ANTHROPIC_API_KEY
An API key for accessing the Anthropic Claude API.
defang config set ANTHROPIC_API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Model Context Protocol (MCP) Chatbot
Short Description: An MCP (Model Context Protocol) chatbot assistant built with Next.js, Python, and Anthropic Claude.
Tags: MCP, Next.js, Python, Quart, Claude, AI, Anthropic, TypeScript, React, JavaScript
Languages: nodejs, python
Metabase & Postgres
Metabase is a simple and powerful analytics tool which lets anyone learn and make decisions from their company’s data. This sample demonstrates how to deploy Metabase with Defang. In development, we run a postgres container and in production, we use a managed postgres service. To build the sample, we used Neon, because of their simplicity and generous free tier.
Prerequisites
- Download Defang CLI
- Have a managed database service configured and have the connection details ready.
- (optional) If you are using Defang BYOC, make sure you have properly authenticated your AWS account.
Local
For development, we use a Postgres container. The Postgres container is defined in the compose.dev.yaml
file. The Metabase container is defined in the compose.yaml
file, with some overrides in the compose.dev.yaml
file so it can correctly connect to the development database container.
To start the development environment, run docker compose -f ./compose.yaml -f ./compose.dev.yaml up
. This will start the Postgres container and the Metabase container. Metabase will be available at http://localhost:3000
.
Since Metabase is a self contained application, there isn't an actual development process, but you can use the development environment to see how Metabase works.
Deploying
- Open the terminal and type
defang login
- Add your database connection details using
defang config
by typingdefang config set <CONFIG_VAL>
where<CONFIG_VAL>
is the each of the followingMB_DB_DBNAME
,MB_DB_HOST
,MB_DB_PORT
,MB_DB_USER
,MB_DB_PASS
(to set the database name, host, port, user, and password respectively). For exampledefang config set MB_DB_DBNAME
and pasting your database name. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Metabase & PostgreSQL
Short Description: A simple Metabase configuration with a PostgreSQL database.
Tags: Metabase, PostgreSQL, Analytics, Database
Languages: SQL
Next.js
A basic Next.js app with a Dockerfile and compose.yaml ready to deploy to AWS with Defang.
Steps
- Install Defang
- Authenticate with Defang
- (optional) Authenticate with AWS
- Run
defang compose up
in the root of this project
Static Files (Experimental)
This example supports deployment to AWS as a static site. Static files will be copied to an S3 bucket. In the affordable deployment mode (the default), the static files will be served over HTTP from an S3 bucket.
Note that some top-level domains (TLDs), such as .app
, require HSTS, which will disallow browsers from accessing the site over HTTP. If you want to use such a TLD, you must serve the static files over HTTPS by using either the balanced or high_availability deployment mode.
To serve the static files over HTTPS, use either the balanced or high_availability deployment mode, which will create a CloudFront distribution in front of the S3 bucket.
To deploy this project as a static site, run:
defang compose up -f compose.static.yaml --provider=aws --mode=balanced
Title: Next.js
Short Description: A basic Next.js app.
Tags: Next.js, React, Docker, Node.js, TypeScript, JavaScript, Static
Languages: nodejs
Next.js Blog
This template is a starter project developed using Next.js designed to make it easy to launch a blog. It offers an excellent starting point to help you publish your content by simply modifying the MDX files included in _posts
directory. We have prepared all the necessary files for deployment. By spending just a few minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live in no time!
Essential Setup Files
- A Dockerfile to describe the basic image of your applications.
- A docker-compose file to define and run multi-container Docker applications.
- A .dockerignore file to comply with the size limit (10MB).
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account
Plus, make sure that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
.
A Step-by-Step Guide
- Edit your content in the
_posts
directory - Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Now your application will be launched
Title: Next.js Blog
Short Description: A starter project developed using Next.js designed to make it easy to launch a blog.
Tags: Next.js, Blog, Node.js, React, MDX, TypeScript, JavaScript
Languages: nodejs
Next.js & Claude
This sample shows a Next.js and Claude application deployed using Defang. It uses Anthropic API for its chatbot functionality.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
ANTHROPIC_API_KEY
An API key for Anthropic AI.
defang config set ANTHROPIC_API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Next.js & Claude
Short Description: A fun chatbot created with Next.js and Claude.
Tags: Next.js, TypeScript, React, JavaScript, Chatbot, Claude, AI, Anthropic
Languages: TypeScript
Next.js CV
This is a sample of a Next.js CV web application, deployed with Defang.
The template is based off of the repository https://github.com/BartoszJarocki/cv on GitHub.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Next.js CV
Short Description: A Next.js web app that displays a minimalist CV.
Tags: Next.js, React, TypeScript, JavaScript
Languages: nodejs
Nextra
This template is a documentation starter project developed using Nextra, designed to streamline the creation of your documentation and quickly build a digital knowledgebase. You can add content easily by simply adding markdown files. This code-free solution requires no adjustments to the basic structure. We have prepared all the essential files for deployment. By spending just a few minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live in no time!
Essential Setup Files
- A Dockerfile to describe the basic image of your applications.
- A docker-compose file to define and run multi-container Docker applications.
- A .dockerignore file to comply with the size limit (10MB).
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account
Plus, make sure that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
.
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Now your application will be launched
Title: Nextra
Short Description: A documentation starter project developed using Nextra designed to streamline the creation of your documentation.
Tags: Next.js, Documentation, Nextra, Knowledgebase, Node.js, JavaScript, TypeScript
Languages: nodejs
Next.js & Postgres
This is a sample Next.js application that uses Postgres as a database. It is a simple example that demonstrates how to connect to a Postgres database from a Next.js application: on each request it takes the user's IP address, geo-locates it, and stores the result in the database, then displays the last 20 results on the home page.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Configuration
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
A password that will be used to connect to the Postgres database.
Deploying
- Open the terminal and type
defang login
- Use the
defang config
command to setup environment variables. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Next.js & Postgres
Short Description: A sample Next.js application that uses Postgres as a database.
Tags: Next.js, Postgres, Database, Node.js
Languages: TypeScript, JavaScript
Next.js-Railpack
A simple Next.js app with a compose.yaml, ready to deploy to AWS using Defang. The container image is automatically built by Railpack.
Steps
- Install Defang
- Authenticate with Defang
- (optional) Authenticate with AWS
- Run
defang compose up
in the root of this project
Title: Next.js
Short Description: A basic Next.js app.
Tags: Next.js, React, Node.js, TypeScript, JavaScript, Static, Railpack
Languages: nodejs
NocoDB
This sample demonstrates how to deploy a Nocodb instance with Defang. It's an open source alternative to AirTable, that makes it easy to organize and manage data.
Prerequisites
- Download Defang CLI
- A Postgres database
- S3 bucket and credentials, or S3 compatible alternative
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
Configuration
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
NC_DB
Postgres database URL. NocoDB uses an odd, custom format for this. It should look like this: pg://my.pg.hostname.com:5432?u=postgres&p=password&d=nocodb&ssl=true
. Neon has a free tier and is easy to set up.
NC_S3_ENDPOINT
S3 endpoint URL. Wasabi is a simple option for this if you don't already have an S3 bucket or don't have an AWS account you can use.
NC_S3_BUCKET_NAME
Name of the S3 bucket.
NC_S3_REGION
Region of the S3 bucket.
NC_S3_ACCESS_KEY
Access key for the S3 bucket.
NC_S3_ACCESS_SECRET
Access secret for the S3 bucket.
Deploying
- Open the terminal and type
defang login
- Use the deploy the configuration values specified above using the
defang config set
command. - Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Development
For development, we use a local postgres container and a volume mount for file uploads. To run the app locally, just run:
docker compose --file compose.dev.yaml up --build
Title: NocoDB
Short Description: An open source alternative to AirTable.
Tags: NocoDB
Languages: Dockerfile
Node.js & SocketIO
This is a minimal chat application that shows how to use Socket.IO with Node.js with minimal code deployed with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC
Title: Node.js & SocketIO
Short Description: A minimal chat application that shows how to use Socket.IO with Node.js.
Tags: Node.js, Chat, Socket.IO, JavaScript
Languages: nodejs
Node.js & Express
This Node.js application, built with Express.js, is designed to inspect and display detailed information about incoming HTTP requests. It supports all HTTP methods and provides insights into the request path, method, headers, query parameters, and body. Note alongside your project, you should also include a package.json file that includes the relevant metadata such as package dependencies, scripts, project verrsions so that the Dockerfile can install necessary dependencies.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Node.js & Express
Short Description: A Node.js application that inspects and displays detailed information about incoming HTTP requests.
Tags: Node.js, Express, HTTP, Request, Inspector, JavaScript
Languages: nodejs
Node.js Express Form
This is a basic Node.js application using the Express framework to demonstrate handling a form submission. The application serves an HTML form where users can input their first name and then greets them personally upon submission.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js Express Form
Short Description: A Node.js application that handles form submissions using the Express framework.
Tags: Node.js, Express, HTTP, JavaScript
Languages: nodejs
Node.js HTTP Server
This example shows how to build a minimal Node.js application using the Node.js runtime.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js HTTP Server
Short Description: A simple Node.js application that creates an HTTP server.
Tags: Node.js, HTTP, Server
Languages: nodejs
Node.js & OpenAI
A simple Node.js and OpenAI app deployed using Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
OPENAI_KEY
An API key to access the OpenAI API.
defang config set OPENAI_KEY
Testing
Below are some useful commands for testing.
echo "Hello" | curl -H "Content-Type: text/plain" -d @- https://xxxxxxxx/prompt
or alternatively,
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js & OpenAI
Short Description: A simple Node.js application that interacts with the OpenAI API.
Tags: Node.js, OpenAI, API, JavaScript
Languages: nodejs
Node.js & React & PostgreSQL
This sample project demonstrates how to deploy a full-stack application using React for the frontend, Node.js for the backend, and PostgreSQL for the database.
In this sample, we have set up the essential files you need to deploy in production using Neon to host your database. We use a connection string to connect Neon to your code. By replacing the pre-configured connection string at .env and at the compose file to yours, you will be ready to deploy this sample with Neon.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up --build
Or run without using Docker by doing the following:
- run
npm install
to install the nodejs dependencies in both theclient
directory and theserver
directory - create or modify the .env file in both the
client
directory and theserver
directory with localhost, or create a .env.local to override the .env file. - run
npm start
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
DATABASE_URL
A connection to the database, which should be in the format of postgres://username:password@host:port/dbname
.
defang config set DATABASE_URL
REACT_APP_API_URL
A URL for the React App. For this, you will need to update the compose.yaml
file to replace <YOUR_USERNAME>
with your username, which you can get by running defang whoami
.
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js & React & PostgreSQL
Short Description: A full-stack to-do list application.
Tags: Node.js, React, Full-stack, PostgreSQL, JavaScript, SQL
Languages: nodejs
Node.js & REST API
This is a simple Node.js application that uses Express.js to create a REST API. It has two endpoints: one that returns a status message, and another that fetches and returns average interest rates data from the U.S. Department of the Treasury's Fiscal Data API.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will not need to provide configuration.
If you wish to provide configuration, see below for an example of setting a configuration for a value named API_KEY
.
defang config set API_KEY
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js & REST API
Short Description: A simple Node.js application that creates a REST API and fetches data from the U.S. Department of the Treasury's Fiscal Data API.
Tags: Node.js, REST API, JavaScript
Languages: nodejs
Node.js & S3
A simple Node.js and AWS S3 app deployed using Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
AWS_ACCESS_KEY
An API key to access AWS services.
defang config set AWS_ACCESS_KEY
AWS_SECRET_KEY
An API key to access AWS services.
defang config set AWS_SECRET_KEY
Testing
Below is a useful command for testing.
curl -X POST -H 'Content-Type: application/json' -d '{ "first_name" : "jane", "last_name" : "doe" }' https://xxxxxx/upload
curl https://xxxxxx/download
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
Title: Node.js & S3
Short Description: A simple Node.js application that uploads and downloads files from AWS S3.
Tags: Node.js, S3, AWS, JavaScript
Languages: nodejs
Nounly
Nounly (also known as Noun.ly) is a URL shortener website built with Go, JavaScript and Redis, and can be deployed with Defang as a sample.
The URL shortener appends a noun to the end of a Defang-deployed URL to create the new shortened URL. For reference, you can view the real Noun.ly website here.
"Share the web through words." - Creator of Nounly
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up --build
Configuration
For this sample, you will need to provide the following configuration:
Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
PROJECT_HONEYPOT_KEY
A Project Honey Pot API key that is used for anti-spamming. It is optional, but please include a non-empty string value.
defang config set PROJECT_HONEYPOT_KEY
SHARED_SECRETS
A JSON object string of shared secrets that are used for API clients. It is optional, and the default value is {}
if you do not have any shared secrets.
defang config set SHARED_SECRETS
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC
If you want to deploy to your own cloud account, you can use Defang BYOC.
Title: Nounly
Short Description: A URL shortener website built with Go, JavaScript, and Redis.
Tags: Go, JavaScript, Redis, URL shortener
Languages: golang, javascript
Ollama
This sample demonstrates how to deploy Ollama with Defang, along with a Next.js frontend using the AI SDK for smooth streaming conversations. By default it runs a very small model (llama3.2:1b
) which can perform well with just a CPU, but we've included lines that you can uncomment in the compose file to enable GPU support and run a larger model like gemma:7b
. If you want to deploy to a GPU powered instance, you will need to use your own AWS account with Defang BYOC.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.dev.yaml up
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the defang playground by opening up your terminal and typing defang up
.
Keep in mind that the playground does not support GPU instances.
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run
defang up
in a terminal that has access to your AWS environment variables.
Title: Ollama
Short Description: Ollama is a tool that lets you easily run large language models.
Tags: AI, LLM, ML, Llama, Mistral, Next.js, AI SDK,
Languages: Typescript
Phoenix & Postgres
Defang is the easiest way to deploy containerized apps like this Phoenix + Postgres sample to AWS. This is a sample Phoenix application that uses a PostgreSQL database. The sample doesn't add anything to the database, but is based off of the default Phoenix getting started instructions which add a postgres database to the application.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose -f compose.yaml -f compose.dev.yaml up --build
This will run Phoenix in development mode. If you need to run any commands in the container, after you have run the command above and started the container, you can run the command in a new terminal:
docker compose -f compose.yaml -f compose.dev.yaml exec phoenix bash
Deploying
- Open the terminal and type
defang login
- Provide values for
SECRET_KEY_BASE
andDATABASE_URL
SECRET_KEY_BASE
is a secret key used by Phoenix to sign cookies and other things. You can generate one by runningdocker compose -f compose.yaml -f compose.dev.yaml run --rm phoenix mix phx.gen.secret
DATABASE_URL
is the connection string for your PostgreSQL database. It should look something likeecto://username:password@hostname/dbname
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Phoenix & PostgreSQL
Short Description: A sample Phoenix application that uses a PostgreSQL database.
Tags: Phoenix, PostgreSQL, Database, Elixir
Languages: Elixir
Pulumi
This basic example shows you how to use the Defang Pulumi provider to deploy the nodejs-http sample with Defang.
Prerequisites
Install the Defang CLI by following the instructions in the Defang CLI documentation.
Install the dependencies:
npm install
Deploying
Create a new stack:
pulumi stack init production
Login to Defang:
defang login
Deploy the application:
pulumi up
Title: Pulumi
Short Description: A basic Pulumi example.
Tags: Pulumi, Node.js, HTTP, Server, TypeScript
Languages: nodejs
Pulumi & Remix & Postgres
In this example, we run a Remix application connected to a Postgres database using Prisma as an ORM. When we deploy our service to Defang, we also deploy a Postgres service and database using Aiven so we can run our full application in the cloud.
Running Locally
To run this example locally, you'll need to have a Postgres database. You can run one locally with Docker:
docker run -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres
Create a .env
file with the following:
DATABASE_URL="postgresql://postgres:password@localhost:5432/postgres?schema=public"
Then run npm install
and npm run dev
in the remix
directory to start the application.
Deploying to Defang
First, cd
into the pulumi
directory and make sure you're logged into Defang with defang login
and into Pulumi with pulumi login
.
Next, head to your Aiven account and create an api token, then run the following command to store it in your Pulumi stack config:
pulumi config set --secret aiven:apiToken <YourToken>
You'll also need to make sure you have an Aiven organization with a billing method attached to a billing group. Get the organization id and the billing group id and add them to your config with the following commands:
pulumi config set --secret aivenOrganizationId <OrgId>
pulumi config set --secret aivenBillingGroupId <BillingGroupId>
Now, run pulumi up
to deploy your application to Defang and Aiven! Head to the portal to check on status, or run defang services
.
Title: Pulumi & Remix & PostgreSQL
Short Description: A full-stack example using Remix, Prisma, and Aiven.
Tags: Full-stack, Remix, Prisma, Aiven, PostgreSQL, Pulumi, Node.js, TypeScript, SQL
Languages: nodejs
Flask & Form Submission
This Flask application provides a basic example of handling form submissions. It displays an HTML form where users can input their first name. Upon submission, the application greets the user by name on a new page. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip.
Essential Setup Files
- A Dockerfile.
- A compose file to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). (compose.yaml file)
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account (optional)
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Your app should be up and running with Defang in minutes!
Title: Python & Form
Short Description: A short Python example for form submission in Flask.
Tags: Python, Flask, Form
Languages: python
Python & Implicit & GPU
This Music Recommendation API provides artist recommendations based on collaborative filtering using the Alternating Least Squares (ALS) algorithm from the implicit library. The dataset utilized is from Last.fm. Note that alongside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip. It demonstrates how to use a GPU with Python and the implicit library with Defang.
Essential Setup Files
- A Dockerfile.
- A compose file to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). (compose.yaml file)
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account (optional)
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Your app should be up and running with Defang in minutes!
Title: Python & Implicit & GPU
Short Description: A Music Recommendation API that provides artist recommendations based on collaborative filtering using the ALS algorithm from the Implicit library, leveraging a GPU.
Tags: Music, Recommendation, API, Collaborative Filtering, Implicit, GPU, Python
Languages: python
Python & Flask & HTTP
This Flask application is designed to inspect and return detailed information about HTTP requests. It supports both GET and POST methods, providing insights into the request path, method, headers, query parameters, and body. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip.
Features
- Support both GET and POST HTTP methods
- Detailed information about the request, including path, method, headers, query parameters, and body.
Essential Setup Files
- A Dockerfile.
- A compose file to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). (compose.yaml file)
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account (optional)
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Your app should be up and running with Defang in minutes!
Title: Python & Flask & HTTP
Short Description: A Flask application that inspects and returns detailed information about HTTP requests.
Tags: Flask, HTTP, Python
Languages: python
Python & Flask & OpenAI
Setup
This sample requires an API key to access the OpenAI API. The name of the config value is referenced in the compose.yaml file. To provide a value for it, you can use the Defang CLI like this:
defang config set --name OPENAI_KEY
and then enter the value when prompted.
Testing
echo "Hello" | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
or
cat prompt.txt | curl -H "Content-Type: application/text" -d @- https://xxxxxxxx/prompt
Title: Python & Flask & OpenAI
Short Description: An app that demonstrates how to use the OpenAI API with Python and Flask.
Tags: Python, Flask, OpenAI, AI, Python
Languages: python
Python & REST API
This Flask application fetches average interest rates from the Fiscal Data Treasury API. It provides endpoints to check the status of the API and to retrieve the latest average interest rates. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip.
Features
Endpoint to check API status. Endpoint to fetch average interest rates from the Fiscal Data Treasury API.
Essential Setup Files
- A Dockerfile.
- A compose file to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). This is optional
Prerequisite
- Download Defang CLI
- If you are using Defang BYOC, make sure you have properly authenticated your AWS account (optional)
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Your app should be up and running with Defang in minutes!
Title: Python & REST API
Short Description: A Flask application that fetches average interest rates from the Fiscal Data Treasury API.
Tags: Flask, REST API, Python
Languages: python
Python & Flask & AWS S3
This sample requires an API key to access AWS S3. The name of the config values is referenced in the compose.yaml file. To provide a value for it, you can use the Defang CLI like this:
defang config set --name AWS_ACCESS_KEY
defang config set --name AWS_SECRET_KEY
and then enter the value when prompted.
Testing
curl -X POST -H 'Content-Type: application/json' -d '{ "first_name" : "jane", "last_name" : "doe" }' https://xxxxxx/upload
curl https://xxxxxx/download
Title: Python & Flask & AWS S3
Short Description: An app that demonstrates how to upload and download files from AWS S3 using Python and Flask.
Tags: Python, Flask, AWS, S3
Languages: python
Ruby on Rails
This template is a member list project developed using Ruby on Rails, offering a starting point to help you quickly build your team management system. We have prepared all the essential files for deployment. By spending less than 10 minutes setting up the environment, as detailed in the prerequisites, and executing the commands in our step-by-step guide, your website will be ready to go live to the world!
Essential Setup Files
- A Dockerfile to describe the basic image of your applications.
- A docker-compose file to define and run multi-container Docker applications.
- A .dockerignore file to comply with the size limit (10MB).
Development Using Dev Containers
- Open the working directory with Visual Studio Code or any editor which supports Dev Containers.
- Click on the bottom left corner of the window where you see "Reopen in Container".
- Open up a shell in the VS Code terminal and run
docker compose -f compose.dev.yaml up --build
.
Configuration
For this sample, you will need to provide the following configuration. Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
POSTGRES_PASSWORD
This password will be used to initialize the PostgreSQL database and to connect to it.
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the defang playground by opening up your terminal and typing defang up
.
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run
defang --provider=aws up
in a terminal that has access to your AWS environment variables.
Title: Ruby on Rails
Short Description: A basic member list project developed using Ruby on Rails.
Tags: Ruby, Rails
Languages: Ruby
React
This sample shows how to get a simple React app up and running with Defang. It includes Vite and ESLint, which are common build tools for React development.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command (make sure you've got npm
and Node.js installed):
npm install
npm run dev
To run it using a Docker container, you can use the following command:
docker compose up --build
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: React
Short Description: A minimal React app running on Defang.
Tags: React, Vite, JavaScript, Frontend
Languages: JavaScript
React-Vite-Railpack
This sample shows how to get a simple React app up and running with Defang. It includes Vite and ESLint, which are common build tools for React development. The container image is automatically built by Railpack.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate with your cloud provider account
Development
To run the application locally, you can use the following command (make sure you've got npm
and Node.js installed):
npm install
npm run dev
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: React
Short Description: A minimal React app running on Defang.
Tags: React, Vite, JavaScript, Frontend, Railpack
Languages: JavaScript
Rocket
This sample demonstrates how to deploy a very simple Rocket app. Rocket is a web framework for Rust.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticate against your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command:
docker compose up
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the defang playground by opening up your terminal and typing defang up
.
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run
defang --provider=aws up
in a terminal that has access to your AWS environment variables.
Title: Rocket
Short Description: A simple Rocket app.
Tags: Rocket
Languages: Rust
Sailsjs
This sample demosntrates how to deploy a very basic Sailsjs sample with Defang. The sample simply outputs hello world on the webpage.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
Deploying
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Development
For development, we use a local container. This can be seen in the compose.yaml document. To run the sample locally after cloning the respository, you can run on docker by using the following command:
- docker compose -f compose.dev.yaml up --build
Title: Sails.js
Short Description: A short hello world application demonstrating how to deploy Sails.js onto Defang.
Tags: Sails.js, Node.js
Languages: nodejs
Sails.js & PostgreSQL
This sample project demonstrates how to deploy
Sailsjs with Defang and connect it to a Postgres database. Furthermore, we emonstrate how to run a local Postgres container during development vs a managed postgres service (Neon). For a quick database set up please go to Neon and follow set up instructions. The sample starts with a no tasks in the database and allows us to add tasks on the fly. It sets wide open permissions on the tables as well so you can start querying or mutating the data right away.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
- (Optional) [Neon CLI] (https://neon.tech/docs/reference/neon-cli)
Deploying production
- Open the terminal and type
defang login
- Add your connection string for the third party postgres database in the DATABASE_URL part of the compose.yaml section
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Development
For development, we use a Postgres container. The Postgres container is defined in the compose.dev.yaml
file. The Neon postgres container is defined in the compose.yaml
file, with some overrides in the compose.dev.yaml
file so it correctly connects to the development database container. To start your own, please have the env variables, POSTGRES_USER
, POSTGRES_PASSWORD
, POSTGRES_DB
, and SESSION_SECRET
ready.
To start the development environment, run:
docker compose -f compose.dev.yaml up --build
Title: Sails.js & PostgreSQL
Short Description: A sample project demonstrating how to deploy a project with PostgreSQL and Sails.js.
Tags: PostgreSQL, Sails.js, SQL, JavaScript
Languages: nodejs
Svelte & Node.js & MySQL
This sample project demonstrates how to deploy a full-stack application using Svelte for the frontend, Node.js for the backend, and MySQL for the database. The project uses Docker to containerize the services, making it easy to run in both development and production environments.
NOTE
This sample showcases how you could deploy a full-stack application with Defang and Svelte and NodeJS. However, it deploys mysql db as a defang service. Defang services are ephemeral and should not be used to run stateful workloads in production as they will be reset on every deployment. For production use cases you should use a managed database like RDS, Aiven, or others. In the future, Defang will help you provision and connect to managed databases.
Essential Setup Files
- Download [Defang CLI] (https://github.com/DefangLabs/defang)
- (optional) If you are using [Defang BYOC] (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated your AWS account.
- (optional for local development) [Docker CLI] (https://docs.docker.com/engine/install/)
Prerequisite
- Download [Defang CLI] (https://github.com/DefangLabs/defang)
- (optional) If you are using Defang BYOC make sure you have properly
- [Docker CLI] (https://docs.docker.com/engine/install/)
- [NodeJS] (https://nodejs.org/en/download/package-manager)
Development
For development, we use a local container. This can be seen in the compose.yaml file and the server.js file where we create a pool of connections. To run the sample locally after clonging the respository, you can run on docker by doing docker compose up --build --build or run without using Docker by doing the following:
- run npm install to install the nodejs dependencies
- create an .env file on the svelte directory specifying the appropriate environment variables.
- run npm start
Editing the database/permissions etc.
If you want to edit the database, such that you can deploy them to production, you should install the mySQL CLI and mySQL workbench to gain access to a GUI so that you can make your changes to the database. After running defang compose up these changes will be reflected.
Deploying
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: Svelte & Node.js & MySQL
Short Description: A full-stack application using Svelte for the frontend, Node.js for the backend, and MySQL for the database.
Tags: Svelte, Node.js, MySQL, Full-stack, JavaScript, TypeScript, SQL
Languages: nodejs
Sveltekit
This sample shows how to get a minimal SvelteKit app up and running with Defang.
Prerequisites
- Download Defang CLI
- Have a managed database service configured and have the connection string ready.
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional - for local development) Docker CLI
Development
To develop this app, you can run the sveltekit commands as you normally would on your local machine in the sveltekit directory. If you plan on adding other services, you might want to run it with docker compose. We have provided a compose.dev.yaml
file and a dev.Dockefile
to help you get started. Just run docker compose -f compose.dev.yaml up --build
to start your Sveltekit app in dev mode in a container.
Deploying
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI. - Your app will be running within a few minutes.
Title: SvelteKit
Short Description: A minimal SvelteKit app running on Defang.
Tags: SvelteKit, TypeScript, JavaScript, Svelte, Node.js, Frontend, TypeScript, JavaScript
Languages: nodejs
Sveltekit & MongoDB
This is a project that demonstrate both client side component rendering and hydration as well as serverside rendering with external API route configuration. Furthermore, there is also a mongodb connection (not hosted on the atlas) to cache the queried results.
NOTE
This sample showcases how you could deploy a full-stack application with Defang and Sveltekit. However, it deploys mongodb as a defang service. Defang services are ephemeral and should not be used to run stateful workloads in production as they will be reset on every deployment. For production use cases you should use a managed database like RDS, Aiven, or others. In the future, Defang will help you provision and connect to managed databases.
Essential Setup Files
- Download [Defang CLI] (https://github.com/DefangLabs/defang)
- (optional) If you are using [Defang BYOC] (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated your AWS account.
- (optional for local development) [Docker CLI] (https://docs.docker.com/engine/install/)
Prerequisite
-
Download [Defang CLI] (https://github.com/DefangLabs/defang)
-
(optional) If you are using Defang BYOC make sure you have properly
-
[Docker CLI] (https://docs.docker.com/engine/install/)
Development
For development, we use a local container. This can be seen in the compose.yaml and /src/routes/api/songs/+server.js file and the server.js file where we create a pool of connections. To run the sample locally after clonging the respository, you can run on docker by doing
- docker compose up --build
A Step-by-Step Guide
- Open the terminal and type
defang login
- Type
defang compose up
in the CLI - Your app should be up and running with Defang in minutes!
Title: SvelteKit & MongoDB
Short Description: A full-stack application using SvelteKit for the frontend and MongoDB for the database.
Tags: SvelteKit, MongoDB, Full-stack, Node.js, JavaScript
Languages: nodejs
Mistral & vLLM
This guide demonstrates how to deploy Mistral using vLLM. You'll need a Hugging Face token to begin.
Prerequisites
- Hugging Face token
Steps
-
Set the Hugging Face Token
First, set the Hugging Face token using the
defang config
command.defang config set --name HF_TOKEN
-
Launch with Defang Compose
Run the following command to start the services:
defang compose up
The provided
compose.yaml
file includes the Mistral service. It's configured to run on an AWS instance with GPU support. The file also includes a UI service built with Next.js, utilizing Vercel's AI SDK.OpenAI SDK: We use the OpenAI sdk, but set the
baseURL
to our Mistral endpoint.Note: The API route does not use a system prompt, as the Mistral model we're deploying currently does not support this feature. To get around this we inject a couple messages at the front of the conversation providing the context (see the
ui/src/app/api/chat/route.ts
file). Other than that, the integration with the OpenAI SDK should be structured as expected.Changing the content: The content for the bot is set in the
ui/src/app/api/chat/route.ts
file. You can edit the prompt in there to change the behaviour. You'll notice that it also pulls fromui/src/app/docs.md
to provide content for the bot to use. You can edit this file to change its "knowledge".
Configuration
- The Docker Compose file is ready to deploy Mistral and the UI service.
- The UI uses Next.js and Vercel's AI SDK for seamless integration.
By following these steps, you should be able to deploy Mistral along with a custom UI on AWS, using GPU capabilities for enhanced performance.
Title: Mistral & vLLM
Short Description: Deploy Mistral with a custom UI using vLLM.
Tags: Mistral, vLLM, AI, Nextjs, GPU, Node.js, TypeScript, JavaScript
Languages: nodejs
Vue.js
This sample shows how to get a minimal Vue.js app up and running with Defang.
Prerequisites
- Download Defang CLI
- (Optional) If you are using Defang BYOC authenticated with your AWS account
- (Optional for local development) Docker CLI
Development
To run the application locally, you can use the following command (make sure you've got npm
and Node.js installed):
npm run dev
To run it using a Docker container, you can use the following command:
docker compose up --build
Deployment
[!NOTE] Download Defang CLI
Defang Playground
Deploy your application to the Defang Playground by opening up your terminal and typing:
defang compose up
BYOC (AWS)
If you want to deploy to your own cloud account, you can use Defang BYOC:
- Authenticate your AWS account, and check that you have properly set your environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
. - Run in a terminal that has access to your AWS environment variables:
defang --provider=aws compose up
Title: Vue.js
Short Description: A minimal Vue.js app running on Defang.
Tags: Vue.js, Vite, Node.js, Frontend, JavaScript
Languages: nodejs