From 60f27bde6d5b97338a66b2702daa4382e26d23fa Mon Sep 17 00:00:00 2001 From: Petrus Han Date: Wed, 30 Oct 2024 08:43:10 +0800 Subject: [PATCH] fix the bug that Opensearch can't be connected (#15) - change the Opensearch setup params - add the new env variables in .env - update README.md --- .env.example | 5 +++++ README.md | 10 +++++++--- configs/index.ts | 3 --- configs/prod.ts | 2 +- configs/stackConfig.ts | 2 +- configs/test.ts | 2 +- lib/resourceProvider/opensearch.ts | 30 ++++++++++++++++++++++++++++++ package-lock.json | 2 -- 8 files changed, 45 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 8af970a..1e795eb 100644 --- a/.env.example +++ b/.env.example @@ -17,6 +17,11 @@ REDIS_SUBNETS= RDS_SUBNETS= OPENSEARCH_SUBNETS= + +OPENSEARCH_ADMINNAME= +OPENSEARCH_PASSWORD= + + # AWS EKS Helm chart repository URL (Version 1.8.1) # Set this ONLY if you are using AWS China regions. Please contact us for assistance. # For more information, visit: https://github.com/aws/eks-charts diff --git a/README.md b/README.md index 7dca1ba..0b6628f 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ Deploy Dify Enterprise on AWS using CDK. - `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. @@ -193,7 +195,9 @@ Deploy Dify Enterprise on AWS using CDK. 12. ### VectorDatabase Configure: - Change the Helm `values.yaml` file, modify the `externalType` section as follows, replace `{openSearch_endpont}` with aws Opensearch instant's **Domain endpoint**, remove `https://` and use the left: + 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 `` and `` with the value you have set in `.env` ```yaml vectorDB: @@ -202,8 +206,8 @@ Deploy Dify Enterprise on AWS using CDK. externalOpenSearch: host: "{openSearch_endpont}" port: 443 - user: "" - password: "" + user: "" + password: "" useTLS: true ``` diff --git a/configs/index.ts b/configs/index.ts index 6d64d4d..0e0ba25 100644 --- a/configs/index.ts +++ b/configs/index.ts @@ -14,8 +14,5 @@ export const config: DifyCDKConfig = { } export const getConstructPrefix = (config: StackConfig) => { - // Generate a 6-character random string consisting of numbers and letters - const randomSuffix = Math.random().toString(36).slice(2, 8).toUpperCase(); - return `${PRODUCT_NAME}-${config.environment}-${AWS_RESOURCE_SUFFIX}`; } \ No newline at end of file diff --git a/configs/prod.ts b/configs/prod.ts index 9f443f5..26b68ce 100644 --- a/configs/prod.ts +++ b/configs/prod.ts @@ -9,7 +9,7 @@ export interface ProdStackConfig extends StackConfig { } export const prodConfig: ProdStackConfig = { - environment: 'Production', + environment: 'Prod', region: process.env.CDK_PROD_REGION || process.env.CDK_DEFAULT_REGION || '', account: process.env.CDK_PROD_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT || '', diff --git a/configs/stackConfig.ts b/configs/stackConfig.ts index e00ddd2..ea637d6 100644 --- a/configs/stackConfig.ts +++ b/configs/stackConfig.ts @@ -8,7 +8,7 @@ import { S3Config } from './constructs/s3Config'; * Basic configuration for a stack */ export interface StackConfig { - environment: "Testing" | "Production"; + environment: "Test" | "Prod"; region: string; account: string; diff --git a/configs/test.ts b/configs/test.ts index e4294d1..9095760 100644 --- a/configs/test.ts +++ b/configs/test.ts @@ -13,7 +13,7 @@ export interface TestStackConfig extends StackConfig { } export const testConfig: TestStackConfig = { - environment: 'Testing', + environment: 'Test', region: process.env.CDK_TESTING_REGION || process.env.CDK_DEFAULT_REGION || '', account: process.env.CDK_TESTING_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT || '', diff --git a/lib/resourceProvider/opensearch.ts b/lib/resourceProvider/opensearch.ts index 9200ffc..f33fff4 100644 --- a/lib/resourceProvider/opensearch.ts +++ b/lib/resourceProvider/opensearch.ts @@ -1,6 +1,7 @@ import * as blueprints from '@aws-quickstart/eks-blueprints'; import * as cdk from 'aws-cdk-lib'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as iam from 'aws-cdk-lib/aws-iam'; import * as opensearch from 'aws-cdk-lib/aws-opensearchservice'; import { getConstructPrefix } from '../../configs'; import { DESTROY_WHEN_REMOVE } from '../../configs/constants'; @@ -14,10 +15,12 @@ interface OpenSearchProps { export class OpensearchResourceProvider implements blueprints.ResourceProvider { private readonly config: StackConfig; private readonly vpc: ec2.IVpc; + private readonly domainName: string; constructor(readonly props: OpenSearchProps) { this.vpc = props.vpc; this.config = props.config; + this.domainName = `${getConstructPrefix(props.config)}-Domain`.toLowerCase(); } provide(context: blueprints.ResourceContext): opensearch.IDomain { @@ -66,9 +69,18 @@ export class OpensearchResourceProvider implements blueprints.ResourceProvider