Skip to main content
Deploy Dify Enterprise on AWS using CDK.

Components

Testing Deployment

Production Deployment

Deployment

The whole process is expected to take 60 mins
  1. Configure AWS CLI:

    Install and configure the AWS CLI:
  2. Clone this repository:

  3. Install NodeJS Dependencies:

  4. Configure environment variables:

    Modify the environment variable values in the .env file.
    • ENVIRONMENT: Specifies the deployment environment; must be either test or prod.
    • CDK_DEFAULT_REGION: The AWS region where Dify Enterprise will be deployed.
    • CDK_DEFAULT_ACCOUNT: Your AWS account ID.
    • DEPLOY_VPC_ID: The ID of an existing VPC for deployment. If not set, CDK will create one for you.
    • Note: If using an existing VPC
      • Make sure you have 2 or more public subnets for Application Load Balancer, and 2 or more private subnets can access internet(associated with NAT) to pull docker image from internet.
      • Add Tag for the subnets(Otherwise, Step 6 will show WARN about auto-tag failed, which will result in the Application Load Balancer failing to be created successfully.):
    • Subnets Configuration (DEPLOY_VPC_ID required, comma-separated without spaces, private subnets is recommended by AWS security best practices):
      • EKS_CLUSTER_SUBNETS: Subnet IDs for the EKS control plane. Requires at least 2 subnets in different Availability Zones (AZs).
      • EKS_NODES_SUBNETS: Subnet IDs for the EKS worker nodes. Requires at least 2 subnets in different AZs.
      • REDIS_SUBNETS: Subnet IDs for Redis deployment.
      • RDS_SUBNETS: subnet ids for RDS database. (At least 2 with different AZs)
      • OPENSEARCH_SUBNETS: Subnet IDs for OpenSearch deployment.
      • OPENSEARCH_ADMINNAME: OpenSearch Domain master ame.
      • OPENSEARCH_PASSWORD: OpenSearch Domain master password.
    • AWS_EKS_CHART_REPO_URL: (For AWS China regions ONLY) The AWS EKS Helm chart repository URL.
    • RDS_PUBLIC_ACCESSIBLE: Set to true to make RDS publicly accessible (NOT RECOMMENDED).
    Note:
    • If you are using AWS China regions, you must configure the AWS_EKS_CHART_REPO_URL for proper functionality. Please contact Dify Team for the URL.
    • It is recommended to use an existing VPC for easier resource access.
  5. CDK Bootstrap:

    Initialize the CDK environment:
  6. CDK Deploy:

    • Deploy Dify Enterprise:
  7. Update AWS EKS Access Permissions:

    1. Navigate to the EKS Cluster panel, select the “Access” menu, and click on “Manage access”:
    1. In the “Manage access” dialog, select “EKS API and ConfigMap,” then click “Save Changes.”
    2. In the IAM Access Entries panel, click “Create access entry”:
    1. Add your IAM user and assign the following permissions:
      • AmazonEKSAdminPolicy
      • AmazonEKSAdminViewPolicy
      • AmazonEKSClusterAdminPolicy
  8. Configure kubeconfig to access the Kubernetes (K8S) cluster locally:

    Adjust the region and name parameters according to your deployment:
    • region: The AWS region where your cluster is deployed.
    • name: The EKS cluster name .
  9. Data Persistence Configure:

    Change the Helm values.yaml file. To enable it, modify the persistence section as follows, replace {your-region-name} and {your-s3-bucket-name} with the name of resource created by CDK, make sure you have turn useAwsManagedIam on:
  10. Database Configure:

    Change the Helm values.yaml file, remove postgre section, and modify the externalPostgres section as follows, replace {your-postgres-endpoint} and {your-postgres-password} with data stored in the Secret Manager of AWS:
  11. Redis Configure:

    Change the Helm values.yaml file, remove redis section, and modify the externalRedis section as follows, replace {your-redis-host} with Primary endpoint in console of ElastiCache-Redis OSS caches Note: remove the port number of the Primary endpoint
  12. VectorDatabase Configure:

    Change the Helm values.yaml file, modify the externalType section as follows:
    1. replace {openSearch_endpont} with aws Opensearch instant’s Domain endpoint, remove https:// and use the left.
    2. replace the <OPENSEARCH_ADMINNAME> and <OPENSEARCH_PASSWORD> with the value you have set in .env
  13. Set docker image pull secret

    You need to set the docker image pull secret before installing Dify Enterprise. Note: If you haven’t got the username and password, please contact us, email address:Support@dify.ai
  14. TLS

    For testing:

    If you are just testing the deploy process, you can just ignore this step and go on.

    For production:

    Go to AWS ACM to require the certificates of the domain you declared in helm chart configuration file values.yaml:
    they are:
    go to your domain service provider (e.g. cloud flare, aws route53, etc.) and setup the cname to prove your ownership of these domains. change the values.yaml param: global.useTLS
  15. AWS Load Balancer Configuration

    It is recommended to use an AWS Application Load Balancer (ALB) for your ingress configuration in the Helm values.yaml file. To enable it, modify the ingress section as follows: For testing:
    For production: refer to: AWS load balancer controller setup
  16. Install Dify Enterprise

    Dify Enterprise is deployed using Helm.
  17. Access Dify Enterprise

    For testing:

    After setting up, get the temperally external IP of the ALB.
    Then add the following line to your /etc/hosts file.

    For production

    Go to your Domain service provider, and set up DNS to the ALB address(Go to AWS-EC2-Load Balancer to get the dns of alb):
  18. Verify Installation

    Warning: You have to set up Dify Console http://console.dify.local first before login to Dify Enterprise Dashboard http://enterprise.dify.local.
    • Dify Console: visit http://console.dify.local and finish the installation.
    • Enterprise Dashboard: visit http://enterprise.dify.local, and login with the default email and password. You can change the password after login.

Destroy

The process may take 20 mins.
Destroy the deployment for the environment specified in the .env file under ENVIRONMENT.
Note: login to AWS console, review the VPC, and make sure the VPC created by CDK has destroyed, if not, please Check Cloudformation and perform the deletion operation.

Advanced Configuration

Advanced Configuration

To customize deployment configurations, modify the test.ts file for the testing environment or the prod.ts file for the production environment.