|
| 1 | +# All About Lambda Response Streaming |
| 2 | +This repo consists of 3 use cases for response streaming |
| 3 | +1. Streaming data from DynamoDB. |
| 4 | +2. Streaming data from ChatGPT and comparing it to a regular API response. |
| 5 | +3. Streaming data from Bedrock on a custom python lambda runtime and comparing it to ChatGPT Streaming. |
| 6 | + |
| 7 | +# Pre Requisites |
| 8 | +- AWS SAM CLI |
| 9 | +- ShelbySAM - `npm i -g @antstackio/shelbysam` |
| 10 | +- Docker |
| 11 | +- Python3 |
| 12 | +- You need to add openapi secrets in AWS secrete manager service: |
| 13 | + - `CHAT_GPT` as secret name. |
| 14 | + - chat gpt api key as `API_KEY` secret. |
| 15 | + - chat gpt org id as `ORG_ID` secret. |
| 16 | + |
| 17 | + |
| 18 | +# Initialization |
| 19 | + |
| 20 | +## samconfig.toml |
| 21 | +The path to the file is `/backend/samconfig.toml`. This file contains the stack name, the s3 prefix, and the region of deployment. Note that Amazon Bedrock is supported in only 5 regions, so choose your region carefully |
| 22 | + |
| 23 | +## parameters |
| 24 | +The path to parameter file is `/backend/infra_resources/Parameters.yaml`. Change the parameter values as required. |
| 25 | + |
| 26 | +# Deployment |
| 27 | + |
| 28 | +## Backend |
| 29 | +1. Navigate to the `backend` folder. |
| 30 | +2. Run `shelbysam construct`. After making changes to the paramters and other infra resources, run this command to generate the template.yaml file. |
| 31 | +3. Run `sam build`. Note: When running this command docker must be running as well. The first execution will take a long time as the docker build time is quite large. |
| 32 | +4. Run `sam deploy --resolve-image-repos`. The additional parameter `resolve-image-repos` to sam deploy will automatically fetch the docker images for the lambda. |
| 33 | + |
| 34 | + |
| 35 | +## Backend Post Deployment |
| 36 | +1. Navigate to the root of the repository |
| 37 | +2. Modify the `scan_db_table` and `query_db_table` variable to match the deployment. You can fetch this from the cloudformation output as well. |
| 38 | +3. Run `pip3 install -r requirements.txt` to install the required packages. |
| 39 | +4. Run `python3 uploadToDynamoDb.py`. This will update the base data required for the DynamoDB streaming use case. |
| 40 | + |
| 41 | + |
| 42 | +## Frontend |
| 43 | +1. `cd frontend`. Navigate to the frontend directory. |
| 44 | +2. `npm install`. Install the required packages. |
| 45 | +3. `npm run build`. Build the frontend code. |
| 46 | +4. `aws s3 sync dist s3://{BucketName}`. Replace `BucketName` with the bucket name used for deployment. It is listed as `HostedBucketName` in the output section of the cloudformation. |
| 47 | + |
| 48 | + |
| 49 | +The cloudfront url of the deployed application is available in the output section as `CloudFrontDomainName`. Once the above mentioned steps are completed, you can access the link to use the application. |
0 commit comments