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 build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testsnpx cdk deploy
deploy this stack to your default AWS account/regionnpx cdk diff
compare deployed stack with current statenpx cdk synth
emits the synthesized CloudFormation template