- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS Cloud Development Kit (AWS CDK) v2 Installed
- NodeJS and NPM Installed
- OpenAI API Key
- Amplify CLI installed and configured
- Clone the repository and navigate it:
git clone https://github.com/aws-samples/langchain-agents.git
cd langchain-agents/openai
- Install the project dependencies:
npm install
- Export the OpenAI API Key to store it in AWS SSM Parameter Store:
export OPENAI_API_KEY=<your-openai-api-key>
- The Cognito User Pool Domain must be unique. You can either go to the lib/ai-stack.ts and manually change the name or, if you are on a Mac, run the command below.
timestamp=$(date +%Y%m%d%H%M%S)
sed -i '' "s/ai-domain/ai-domain-$timestamp/" lib/ai-stack.ts
Note: The first time you deploy an AWS CDK app into an environment (account/region), you’ll need to install a “bootstrap stack”. This stack includes resources that are needed for the toolkit’s operation. Use the following command to install the bootstrap stack into the environment:
npx cdk bootstrap
- Use AWS CDK to synthesize an AWS CloudFormation:
npx cdk synth
- Use AWS CDK to deploy the AWS resources for the pattern:
npx cdk deploy
During the deployment you will be asked to confirm the security-sensitive changes. Review it and enter y to deploy the stack and create the resources.
-
Save the following from the outputted values:
a. UserPoolClientIdWeb.
b. UserPoolId.
c. FunctionUrl.
-
Navigate back to the root directory and change directory to the frontend directory:
cd ../front-end
- Install the project dependencies:
npm install
- Configure a new AWS Amplify project:
amplify init
(Optional) If you are running into errors run:
amplify configure
- Import your existing auth resource to your local back-end
amplify import auth
Select the "Cognito User Pool and Identity Pool" option and select the values you saved previously.
- Provision cloud back-end resources with the latest local changes:
amplify push
Create .env.local file to store environmental variable and replace the variables with the Lambda Function URL and corresponding AWS Region:
echo "NEXT_PUBLIC_LAMBDA_URL=<your-lambda-url>" > .env.local
echo "NEXT_PUBLIC_AWS_REGION=<your-aws-region>" >> .env.local
Run application:
npm run dev
- To remove the Amplify auth, run:
amplify remove auth
- To delete the Amplify project and associated backend resources, run:
amplify delete
- To delete the stack, run:
npx cdk destroy
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation