Dify Enterprise Edition 部署指南(AWS)

为确保顺利部署 Dify 企业版,请按照以下基础设施与配置说明进行操作。

一、基础设施要求

需要权限的 AWS 服务:

  • S3
  • ECR

支持的认证方式:

Dify 支持以下两种方式访问 AWS 服务:
  • Access Key 模式(AK/SK):通过环境变量提供凭证
  • IRSA 模式:IAM Roles for Service Accounts,实现更安全、精细的权限控制

二、Access Key 模式配置

步骤 1:准备凭证

创建一个只具备 S3ECR 权限的 IAM 用户,获取其 Access Key 和 Secret Key。

步骤 2:创建 Kubernetes Secret

kubectl create secret generic image-repo-secret --from-file=<path to .aws/credentials>

步骤 3:修改 values.yaml

persistence:
  type: "s3"
  s3:
    endpoint: "https://s3.{region_code}.amazonaws.com"
    region: "{region_code}"
    bucketName: "your_bucket_name"
    useAwsS3: true
    useAwsManagedIam: false
    accessKey: "{your access key}"
    secretKey: "{your secret key}"

# 新增两个服务:
plugin_daemon:
  enabled: true
  replicas: 1
  apiKey: "dify123456"

plugin_connector:
  apiKey: "dify123456"
  imageRepoSecret: "image-repo-secret"
  imageRepoPrefix: "{account_id}.dkr.ecr.{region}.amazonaws.com/dify-ee"
  imageRepoType: ecr
  ecrRegion: "us-west-2"

步骤 4:配置 dify_plugin_daemon 数据库

externalPostgres:
  enabled: true
  address: "rds_address"
  port: "5432"
  credentials:
    plugin_daemon:
      database: "dify_plugin_daemon"
      username: "{user}"
      password: "{password}"
      sslmode: "disable"

步骤 5:升级 Helm Release

helm upgrade dify dify/dify-ee -n default --version 3.0.0

三、IRSA 模式配置

由于企业环境对 Access Key 管控严格,我们推荐使用 AWS Pod Identity (IRSA) 方式来访问资源。

✅ 优势

  • 遵循 AWS 最佳安全实践
  • 可对插件执行环境进行精细化权限管理

🪄 快速配置(推荐)

步骤 1:创建 IAM Role 和 Service Account

  • 前置条件
    • 可用的 AWS 区域以及 EKS 集群
    • 已存在的 S3 Bucket 用于 Dify 文件存储
    • 本地已安装并配置好 kubectl,可访问目标 EKS 集群
    • 本地已安装 AWS CLI 并配置好凭证
🚀 方案 A:运行一键脚本
‼️ 一键脚本仅用于演示和测试,请根据自己的安全要求编写生产脚本。可向 Dify FDE 团队获取此演示脚本。
./irsa_one_click.sh
🔨 方案 B:手动配置
  1. 为 EKS 集群启用 IAM OIDC Provider 请参考 AWS 官方文档,将 EKS 集群与 OIDC 身份提供者关联。此步骤是使用 IRSA 的前提。
  2. 创建 IAM Policy
    项目示例命名描述
    S3 Policy 名称dify-ee-irsa-<cluster_name>-s3-policy对指定 S3 Bucket 具有完全访问权限
    ECR Policy 名称dify-ee-irsa-<cluster_name>-ecr-policy对 ECR 完全访问权限及对 CloudTrail 只读权限
    ECR Policy 名称dify-ee-irsa-<cluster_name>-ecr-pull-only-policy仅允许从 ECR 拉取镜像
  3. 创建关联 Policy 的 IAM Role
    项目示例命名policy
    IAM Role - S3DifyEE-Role-<cluster_name>-s3dify-ee-irsa-<cluster_name>-s3-policy
    IAM Role - S3 + ECRDifyEE-Role-<cluster_name>-s3-ecrdify-ee-irsa-<cluster_name>-s3-policydify-ee-irsa-<cluster_name>-ecr-policy
    IAM Role - ECR Pull-onlyDifyEE-Role-<cluster_name>-ecr-image-pulldify-ee-irsa-<cluster_name>-ecr-pull-only-policy
  4. 为 IAM Role 创建 ServiceAccount
    用途默认名称绑定 IAM Role描述
    dify-api、dify-worker 使用dify-api-saDifyEE-Role-<cluster_name>-s3后端服务访问 S3,例如文件上传等
    dify-plugin-crd 镜像构建使用dify-plugin-crd-saDifyEE-Role-<cluster_name>-s3-ecr访问 S3 并操作插件镜像仓库
    dify-plugin 运行时使用dify-plugin-runner-saDifyEE-Role-<cluster_name>-ecr-image-pull用于拉取插件运行所需镜像

步骤 2:设置环境变量

根据版本发布说明配置所需变量(如 S3_REGIONS3_BUCKET_NAME 等)。

步骤 3:修改 values.yaml

persistence:
  type: "s3"
  s3:
    endpoint: "https://s3.{region_code}.amazonaws.com"
    region: "{region_code}"
    bucketName: "your_bucket_name"
    useAwsS3: true
    useAwsManagedIam: true

api:
  enabled: true
  replicas: 1
  innerApi:
    enabled: true
    apiKey: "dify123456"
  serviceAccountName: "dify-api-sa"

worker:
  enabled: true
  replicas: 1
  serviceAccountName: "dify-api-sa"

plugin_daemon:
  enabled: true
  replicas: 1
  apiKey: "dify123456"

plugin_connector:
  apiKey: "dify123456"
  customServiceAccount: "dify-plugin-build-sa"
  runnerServiceAccount: "dify-plugin-build-run-sa"
  imageRepoPrefix: "{account_id}.dkr.ecr.{region}.amazonaws.com/dify-ee"
  imageRepoType: ecr
  ecrRegion: "us-west-2"

步骤 4:添加插件数据库配置

externalPostgres:
  enabled: true
  address: "rds_address"
  port: "5432"
  credentials:
    plugin_daemon:
      database: "dify_plugin_daemon"
      username: "{user}"
      password: "{password}"
      sslmode: "disable"

步骤 5:根据发布日志升级(安装)

https://langgenius.github.io/dify-helm/#/pages/3_0_0

步骤 6:给应用自建的 ServiceAccount 增加 S3 权限

ServiceAccount 名称:dify-plugin-connector-sa
kubesctl annotate serviceaccount -n {namespace} dify-plugin-connector-sa eks.amazonaws.com/role-arn={arn_of_IAM_S3}
如果你使用./irsa_one_click.sh 创建了 s3 读写的角色 ,这个 arn 会出现在脚本执行的末尾。

步骤7:重启 Dify Deamon Pod

kubectl delete pod {dify-plugin-daemon_name}

注意事项

  • 不支持 Redis Cluster 模式
  • 🌐 EKS 节点需能访问互联网或配置 NAT Gateway