How to Use Your Own Domain
In our latest version of Defang BYOC (Bring Your Own Cloud), you can now use your own domain name. (Currently, this new feature is not applicable to Defang Playground)
Step 1 : Check your Defang BYOC settings
- Make sure you install the latest version of the Defang CLI
- Then, make sure you have properly authenticated your AWS account. The Defang CLI makes use of AWS environment variables like
AWS_PROFILE
,AWS_REGION
,AWS_ACCESS_KEY_ID
, andAWS_SECRET_ACCESS_KEY
, so make sure the correct values are set for those.
If you use the AWS CLI, you can verify that your are authenticated against AWS using the following command (note that the AWS CLI itself is not required to use the defang cli in BYOC mode):
aws sts get-caller-identity
Step 2: Setup a Hosted Zone in AWS Route 53
If you purchased your domain with AWS, you can skip this step.
For Defang to be able to manage your domain, you need to create a public hosted zone in AWS Route 53. It should list four AWS nameservers and should look like this:
Step 3: Configure your DNS settings in your domain registrar
If you purchased your domain with AWS, you can skip this step.
You'll need to create NS records in your domain registrar that point to the AWS Route 53 name servers which we got in the previous step. For example, in CloudFlare, the NS records would look like this:
Step 4: Set up Your Compose File
In your compose file, specify the domain name you want to use, for example
services:
web:
domainname: nextjs.defang.chewydemos.com
build:
context: ./web
dockerfile: Dockerfile
ports:
target: 3000
mode: ingress
Step 5: Deploy
Run the following command to deploy your service:
defang compose up
This will deploy your service and set up the necessary DNS records in Route 53 as seen in the screenshot below as well as provision SSL certificates. You can now access your service at the domain you specified in your compose file.