Invoke OpenAI with Lambda through API Gateway (with rate limit and API key).
You need to create OpenAI API access key at the OpenAI dashboard, and set credit on your account.
To deploy the application, run $ OPENAI_API_KEY=<YOUR_OPENAI_ACCESS_KEY_HERE> npx cdk deploy.
A simple way to test the deployment is to install VSCode extension REST Client.
Create /requests directory and place /requests/test.http file with the following contents:
POST <YOUR_API_URL>/openai
Content-Type: application/json
x-api-key: <YOUR_API_KEY>
{ "message": "whales" }
YOUR_API_URL is printed on the console when you deploy the application through command line. You can retrieve YOUR_API_KEY from AWS console after deployment.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testsnpx cdk deploydeploy this stack to your default AWS account/regionnpx cdk diffcompare deployed stack with current statenpx cdk synthemits the synthesized CloudFormation template