This is an AWS CDK Stack that creates a flow from API Gateway -> Lambda -> SageMaker Endpoint. Using API Gateway and Lambda, you can utilize the SageMaker Endpoint with the same interface as the Upstage Console.
- SageMaker Endpoint: inference service that hosts upstage document-parse model
- API Gateway: REST API interface that handles HTTP requests, manages authentication with API keys, and routes requests to Lambda
- Lambda Function: serverless compute service that processes incoming requests, handles file validation, and communicates with the SageMaker endpoint
- AWS CLI configured with appropriate credentials
- Node.js (>=14.x) and npm installed
- AWS CDK CLI installed (
npm install -g aws-cdk)
- Clone the repository and install dependencies:
git clone https://github.com/UpstageAI/cookbook
cd cookbook/aws/use_cases/aws-cdk/cases/dp-api-gateway
npm ci- Configure environment variables:
cp .env.example .envDeploy all stacks at once:
cdk deploy --allFind the api url from the SetupResourceStageApiGatewayStack25847E5D.ApiUrl in the Output.
Make inference requests by referring to the Document Parse API Reference.
curl -X POST \
-H "Content-Type: multipart/form-data" \
-H "x-api-key: [API_KEY_VALUE]" \
-F "document=@./sample.jpg" \
-F "model=document-parse" \
https://[API_GATEWAY_URL]/v1/document-ai/document-parse | jq
There are some limitations compared to the Upstage Console:
-
File Size Limit:
- Upstage Console: 50MB
- This CDK Stack: 6MB (Lambda payload limit)
-
Timeout:
- Upstage Console: 10 minutes
- This CDK Stack: 29 seconds (API Gateway timeout limit)
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template
