Skip to content

Commit b05157a

Browse files
document estimation
1 parent 833d0fa commit b05157a

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

docs/concepts/estimation.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Cost Estimation
3+
description: Defang enables you to estimate the cost of deploying and running your project before you even create a cloud account.
4+
sidebar_position: 280
5+
---
6+
7+
# Cost Estimation
8+
9+
Defang enables you to estimate the cost of deploying and running your project without needing to create an account with your cloud provider.
10+
11+
:::info
12+
Currently, AWS is the only provider supported for cost estimation. Support for GCP and Digital Ocean is coming soon.
13+
:::
14+
15+
## Generating an Estimate
16+
17+
Navigate your shell to your application's working directory and run
18+
```
19+
defang estimate [--provider aws] [--mode affordable|balanced|high_availability]
20+
```
21+
22+
Here is an example of the output you would see if you estimated the cost deploying the [django-postgres](https://github.com/DefangLabs/samples/tree/main/samples/django-postgres) sample using the `balanced` [deployment mode](/docs/concepts/deployment-modes).
23+
24+
```
25+
defang estimate --provider=aws --mode=balanced
26+
* Packaging the project files for django at /Users/defang/samples/samples/django-postgres/app
27+
* Generating deployment preview
28+
* Preparing estimate
29+
30+
Estimate for Deployment Mode: BALANCED
31+
32+
This mode strikes a balance between cost and availability. Your application
33+
will be deployed with spot instances. Databases will be provisioned using
34+
resources optimized for production. Services in the "internal" network will
35+
be deployed to a private subnet with a NAT gateway for outbound internet access.
36+
37+
Cost Quantity Service Description
38+
$16.43 730 Hours (shared) AWSELB USW2-LoadBalancerUsage
39+
$32.85 730 Hours (shared) AmazonEC2 USW2-NatGateway-Hours
40+
$25.00 100 %Utilized/mo db AmazonRDS USW2-InstanceUsage:db.r5.large
41+
$1.62 14600 GB-Hours django AmazonECS USW2-Fargate-EphemeralStorage-GB-Hours (20 GB * 730 hours)
42+
$1.62 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours (0.50 GB * 730 hours)
43+
-$1.14 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours-SpotDiscount (Estimated @ 70%)
44+
$7.39 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU (0.25 vCPU * 730 hours)
45+
-$5.17 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU-SpotDiscount (Estimated @ 70%)
46+
Estimated Monthly Cost: $78.60 (+ usage)
47+
48+
Estimate does not include taxes or Discount Programs.
49+
To estimate other modes, use defang estimate --mode=affordable|balanced|high_availability
50+
For help with warnings, check our FAQ at https://s.defang.io/warnings
51+
```
52+
53+
This estimate will include a line item for the most significant monthly costs associated with the services described in your project's compose file. If you modify the [`deploy.resources.reservations`](/docs/concepts/compose#deploy) section of your compose file, to increase or decrease replicas, CPU or memory allocations, those changes will be reflected in this estimate.
54+
55+
:::info
56+
Some charges will not be included in this estimate, including charges related to usage like data transfer and storage costs.
57+
:::
58+
59+
## Deploying your project
60+
61+
Now that you have estimated the costs associated with your project. You are ready to deploy to your target cloud.
62+
63+
```
64+
defang compose up [--provider aws|gcp|digitalocean] [--mode affordable|balanced|high_availability]
65+
```
66+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: Estimating AWS Deployment Costs
3+
description: Defang enables you to estimate the cost of deploying and running your project before you even create a cloud account.
4+
sidebar_position: 280
5+
---
6+
7+
# Estimating AWS Deployment Costs
8+
9+
Defang enables you to estimate the cost of deploying and running your project without needing to create an account with your cloud provider. This tutorial will walk through estimating the costs of deploying the [django-postgres](https://github.com/DefangLabs/samples/tree/main/samples/django-postgres) to AWS.
10+
11+
## Clone the sample
12+
13+
```
14+
defang generate # select `django-postgres` (or any other sample) from the list
15+
cd django-postgres # or the name of your project's working directory
16+
```
17+
18+
## Open the compose file
19+
20+
Let's take a quick look at the compose file. There are two services: `db` and `django`. Defang can generate a cost estimate of running the project described by this compose file in the cloud.
21+
22+
Notice that each service has a [`deploy.resources.reservations`](/docs/concepts/compose#deploy) property which describes the service's resource requirements. These numbers will have a significant impact on the cost of running these services in the cloud. The estimation defang generates for you will be sensitive to these numbers.
23+
24+
```yaml
25+
services:
26+
db:
27+
restart: unless-stopped
28+
image: postgres:16
29+
x-defang-postgres: true
30+
environment:
31+
- POSTGRES_DB=django
32+
- POSTGRES_USER=django
33+
- POSTGRES_PASSWORD
34+
ports:
35+
- mode: host
36+
target: 5432
37+
published: 5432
38+
healthcheck:
39+
test: ["CMD", "python3", "-c", "import sys, urllib.request; urllib.request.urlopen(sys.argv[1]).read()", "http://localhost:8000/"]
40+
deploy:
41+
resources:
42+
reservations:
43+
cpus: '0.5'
44+
memory: 256M
45+
46+
django:
47+
restart: unless-stopped
48+
build: ./app
49+
ports:
50+
- mode: ingress
51+
target: 8000
52+
published: 8000
53+
environment:
54+
- DB_HOST=db
55+
- DEBUG=False
56+
- POSTGRES_USER=django
57+
- POSTGRES_DB=django
58+
- POSTGRES_PASSWORD
59+
- SECRET_KEY
60+
- ALLOWED_HOSTS
61+
depends_on:
62+
- db
63+
deploy:
64+
resources:
65+
reservations:
66+
cpus: '0.5'
67+
memory: 256M
68+
```
69+
70+
## Generate an estimate
71+
72+
Generating an estimate is easy. All you need to do is run
73+
74+
```
75+
defang estimate
76+
```
77+
78+
Defang can deploy a project according to different [deployment modes](/docs/concepts/deployment-modes). By default, defang will estimate the cost deploying with the `affordable` mode. If you would like to increase your application's resiliency, you can deploy will the `balanced` or `high_availability` modes. Defang can estimate the cost of deploying using any of these modes.
79+
80+
```
81+
defang estimate --provider aws [--mode affordable|balanced|high_availability]
82+
```
83+
84+
Here is an example of the output you would see if you estimated the cost deploying the [django-postgres](https://github.com/DefangLabs/samples/tree/main/samples/django-postgres) sample using the `balanced` [deployment mode](/docs/concepts/deployment-modes).
85+
86+
```
87+
defang estimate --provider=aws --mode=balanced
88+
* Packaging the project files for django at /Users/defang/samples/samples/django-postgres/app
89+
* Generating deployment preview
90+
* Preparing estimate
91+
92+
Estimate for Deployment Mode: BALANCED
93+
94+
This mode strikes a balance between cost and availability. Your application
95+
will be deployed with spot instances. Databases will be provisioned using
96+
resources optimized for production. Services in the "internal" network will
97+
be deployed to a private subnet with a NAT gateway for outbound internet access.
98+
99+
Cost Quantity Service Description
100+
$16.43 730 Hours (shared) AWSELB USW2-LoadBalancerUsage
101+
$32.85 730 Hours (shared) AmazonEC2 USW2-NatGateway-Hours
102+
$25.00 100 %Utilized/mo db AmazonRDS USW2-InstanceUsage:db.r5.large
103+
$1.62 14600 GB-Hours django AmazonECS USW2-Fargate-EphemeralStorage-GB-Hours (20 GB * 730 hours)
104+
$1.62 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours (0.50 GB * 730 hours)
105+
-$1.14 365 GB-Hours django AmazonECS USW2-Fargate-GB-Hours-SpotDiscount (Estimated @ 70%)
106+
$7.39 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU (0.25 vCPU * 730 hours)
107+
-$5.17 182.50 vCPU-Hours django AmazonECS USW2-Fargate-vCPU-Hours:perCPU-SpotDiscount (Estimated @ 70%)
108+
Estimated Monthly Cost: $78.60 (+ usage)
109+
110+
Estimate does not include taxes or Discount Programs.
111+
To estimate other modes, use defang estimate --mode=affordable|balanced|high_availability
112+
For help with warnings, check our FAQ at https://s.defang.io/warnings
113+
```
114+
115+
This estimate will include a line item for the most significant monthly costs associated with your deployment. Each line item will be associated with a compose service if possible. Some AWS resources will be shared between multiple compose services.
116+
117+
## Deploying your project
118+
119+
Now that you have estimated the costs associated with your project. You are ready to deploy to AWS.
120+
121+
```
122+
defang compose up --provider aws --mode affordable|balanced|high_availability
123+
```
124+

0 commit comments

Comments
 (0)