Skip to content

Commit

Permalink
Move to X86_64 architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
bigadsoleiman committed Aug 18, 2023
1 parent d2e9b94 commit 9d0543b
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 44 deletions.
56 changes: 30 additions & 26 deletions lib/aws-genai-llm-chatbot-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
super(scope, id, props);

// Define common architecture and runtime for all lambda functions
const architecture = lambda.Architecture.ARM_64;
const architecture = lambda.Architecture.X86_64;
const runtime = lambda.Runtime.PYTHON_3_11;

/* --- BASIC USAGE --- */
Expand Down Expand Up @@ -67,6 +67,8 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
messagesTopic,
bedrockRegion,
bedrockEndpointUrl,
architecture,
runtime,
});

// Route all incoming messages to the langchain model interface queue
Expand All @@ -82,17 +84,6 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
}),
);

// User Interface Construct
// This is the web interface for the chatbot
const userInterface = new UserInterface(this, 'WebInterface', {
userPoolId: authentication.userPool.userPoolId,
userPoolClientId: authentication.userPoolClient.userPoolClientId,
identityPoolId: authentication.identityPool.identityPoolId,
webSocketApiUrl: websocketInterface.webSocketApiUrl,
architecture,
// storageBucket: dataBucket, // move this construct to the bottom of the file and uncomment this line to enable file uploads from the user interface to the data bucket for RAG source(s)
});

/* --- OPTIONAL: SELF HOSTED MODELS ON SAGEMAKER --- */
/*
// Falcon Lite example from HuggingFace
Expand Down Expand Up @@ -152,7 +143,6 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {

/* --- OPTIONAL: RAG SECTION --- */
/*
// Create a topic for the data bucket this will act as a message bus only for uploaded/deleted documents
const dataTopic = new sns.Topic(this, 'DataTopic');
Expand Down Expand Up @@ -185,18 +175,6 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
}),
);
// Enable cors for the data bucket to allow uploads from the user interface
// ref: https://docs.amplify.aws/lib/storage/getting-started/q/platform/js/#amazon-s3-bucket-cors-policy-setup
dataBucket.addCorsRule({
allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.PUT, s3.HttpMethods.POST, s3.HttpMethods.DELETE],
allowedOrigins: [userInterface.distributionDomainName],
// allowedOrigins: ['*'], // use this for local web development
allowedHeaders: ['*'],
exposedHeaders: ['x-amz-server-side-encryption', 'x-amz-request-id', 'x-amz-id-2', 'ETag'],
maxAge: 3000,
});
// Route all upload/delete events to the data topic
dataBucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3Notifications.SnsDestination(dataTopic));
dataBucket.addEventNotification(s3.EventType.OBJECT_REMOVED, new s3Notifications.SnsDestination(dataTopic));
Expand All @@ -206,7 +184,7 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
const openSearchVectorSearch = new OpenSearchVectorSearch(this, 'OpenSearchVectorSearch', {
vpc: vpc.vpc,
dataBucket: dataBucket,
collectionName: 'genai-chatbot',
collectionName: 'genai-chatbot-86',
indexName: 'docs',
dimension: 4096, // 4096 is the default dimension for Amazon Titan Embeddings
architecture,
Expand Down Expand Up @@ -266,5 +244,31 @@ export class AwsGenaiLllmChatbotStack extends cdk.Stack {
api: auroraPgVector.api,
});
*/

/* --- USER INTERFACE --- */
// User Interface Construct
// This is the web interface for the chatbot
const userInterface = new UserInterface(this, 'WebInterface', {
userPoolId: authentication.userPool.userPoolId,
userPoolClientId: authentication.userPoolClient.userPoolClientId,
identityPoolId: authentication.identityPool.identityPoolId,
webSocketApiUrl: websocketInterface.webSocketApiUrl,
architecture,
// dataBucket, // uncomment this line to enable file uploads from the user interface to the data bucket for RAG source(s)
});

// Enable cors for the data bucket to allow uploads from the user interface
// ref: https://docs.amplify.aws/lib/storage/getting-started/q/platform/js/#amazon-s3-bucket-cors-policy-setup
/*
dataBucket.addCorsRule({
allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.PUT, s3.HttpMethods.POST, s3.HttpMethods.DELETE],
allowedOrigins: [`https://${userInterface.distributionDomainName}`],
// allowedOrigins: ['*'], // use this for local web development
allowedHeaders: ['*'],
exposedHeaders: ['x-amz-server-side-encryption', 'x-amz-request-id', 'x-amz-id-2', 'ETag'],
maxAge: 3000,
});
*/

}
}
7 changes: 3 additions & 4 deletions lib/model-interfaces/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface LangChainInterfaceProps extends cdk.NestedStackProps {
messagesTopic: sns.Topic;
bedrockRegion?: string;
bedrockEndpointUrl?: string;
architecture: lambda.Architecture;
runtime: lambda.Runtime;
}

export class LangChainInterface extends Construct {
Expand All @@ -29,10 +31,7 @@ export class LangChainInterface extends Construct {
constructor(scope: Construct, id: string, props: LangChainInterfaceProps) {
super(scope, id);

const { messagesTopic, bedrockRegion, bedrockEndpointUrl } = props;

const architecture = lambda.Architecture.ARM_64;
const runtime = lambda.Runtime.PYTHON_3_11;
const { messagesTopic, bedrockRegion, bedrockEndpointUrl, architecture, runtime } = props;

// create secret for 3P models keys
const keysSecrets = new secretsmanager.Secret(this, 'KeySecrets', {
Expand Down
5 changes: 3 additions & 2 deletions lib/rag-sources/aurora-pgvector/document-indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface DocumentIndexingProps extends cdk.NestedStackProps {
dbCluster: rds.DatabaseInstance | rds.DatabaseCluster;
embeddingsEndpoint: sagemaker.CfnEndpoint;
dataBucket: s3.Bucket;
architecture: lambda.Architecture;
}

export class DocumentIndexing extends Construct {
Expand All @@ -26,15 +27,15 @@ export class DocumentIndexing extends Construct {
constructor(scope: Construct, id: string, props: DocumentIndexingProps) {
super(scope, id);

const { vpc, dbCluster, embeddingsEndpoint, dataBucket } = props;
const { vpc, dbCluster, embeddingsEndpoint, dataBucket, architecture } = props;

const dataQueue = new sqs.Queue(this, 'DataQueue', {
visibilityTimeout: cdk.Duration.seconds(600),
});

const documentIndexing = new lambda.DockerImageFunction(this, 'DocumentIndexing', {
code: lambda.DockerImageCode.fromImageAsset(path.join(__dirname, './functions/document-indexing')),
architecture: lambda.Architecture.ARM_64,
architecture,
vpc,
vpcSubnets: vpc.selectSubnets({
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/python:3.11-arm64
FROM public.ecr.aws/lambda/python:3.11

RUN yum update -y
RUN yum install -y git wget
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/python:3.11-arm64
FROM public.ecr.aws/lambda/python:3.11

COPY requirements.txt ./
RUN pip install --upgrade pip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/python:3.11-arm64
FROM public.ecr.aws/lambda/python:3.11

# Install the function's dependencies using file requirements.txt
# from your project folder.
Expand Down
5 changes: 3 additions & 2 deletions lib/rag-sources/aurora-pgvector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ export class AuroraPgVector extends Construct {
});
}

const { dbCluster } = this.createVectorDB({ vpc, indexTypes });
const { dbCluster } = this.createVectorDB({ vpc, indexTypes, architecture });
const { embeddingsEndpoint } = this.createEmbeddingsEndpoint({ vpc });
const documentIndexing = new DocumentIndexing(this, 'DocumentIndexing', {
vpc,
dbCluster,
embeddingsEndpoint,
dataBucket,
architecture,
});
this.ingestionQueue = documentIndexing.ingestionQueue;

this.createAPI({ vpc, dbCluster, embeddingsEndpoint: embeddingsEndpoint, runtime, architecture });
}

private createVectorDB({ vpc, indexTypes }: { vpc: ec2.Vpc; indexTypes: PGVectorIndexType[] }) {
private createVectorDB({ vpc, indexTypes, architecture }: { vpc: ec2.Vpc; indexTypes: PGVectorIndexType[]; architecture: lambda.Architecture }) {
const dbCluster = new rds.DatabaseCluster(this, 'AuroraDatabase', {
engine: rds.DatabaseClusterEngine.auroraPostgres({
version: rds.AuroraPostgresEngineVersion.VER_15_3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/python:3.11-arm64
FROM public.ecr.aws/lambda/python:3.11

RUN yum update -y
RUN yum install -y git wget
Expand Down
4 changes: 2 additions & 2 deletions lib/sagemaker-model/hf-custom-script-model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class HuggingFaceCustomScriptModel extends Construct {
// custom resource lamdba handlers
const onEventHandler = new lambda.Function(this, 'OnEventHandler', {
runtime: lambda.Runtime.PYTHON_3_11,
architecture: lambda.Architecture.ARM_64,
architecture: lambda.Architecture.X86_64,
code: lambda.Code.fromAsset(path.join(__dirname, './build-function')),
handler: 'index.on_event',
});
Expand All @@ -161,7 +161,7 @@ export class HuggingFaceCustomScriptModel extends Construct {
// custom resource lamdba handlers
const isCompleteHandler = new lambda.Function(this, 'IsCompleteHandler', {
runtime: lambda.Runtime.PYTHON_3_11,
architecture: lambda.Architecture.ARM_64,
architecture: lambda.Architecture.X86_64,
code: lambda.Code.fromAsset(path.join(__dirname, './build-function')),
handler: 'index.is_complete',
});
Expand Down
8 changes: 4 additions & 4 deletions lib/user-interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface UserInterfaceProps extends cdk.NestedStackProps {
identityPoolId: string;
webSocketApiUrl: string;
architecture: lambda.Architecture;
storageBucket?: s3.Bucket;
dataBucket?: s3.Bucket;
}

export class UserInterface extends Construct {
Expand All @@ -22,7 +22,7 @@ export class UserInterface extends Construct {
constructor(scope: Construct, id: string, props: UserInterfaceProps) {
super(scope, id);

const { userPoolId, userPoolClientId, identityPoolId, webSocketApiUrl, storageBucket, architecture } = props;
const { userPoolId, userPoolClientId, identityPoolId, webSocketApiUrl, dataBucket, architecture } = props;
const appPath = path.join(__dirname, '.', 'react');

const websiteBucket = new s3.Bucket(this, 'Bucket', {
Expand Down Expand Up @@ -85,12 +85,12 @@ export class UserInterface extends Construct {
},
};

if (storageBucket) {
if (dataBucket) {
awsExports = {
...awsExports,
Storage: {
AWSS3: {
bucket: storageBucket.bucketName,
bucket: dataBucket.bucketName,
region: cdk.Aws.REGION,
},
},
Expand Down

0 comments on commit 9d0543b

Please sign in to comment.