API Gateway

Overview

Create Amazon API Gateway as the entry point for AI service requests.

Create REST API

  1. Navigate to API GatewayCreate APIREST API
SettingValue
API nameielts-ai-api
API typeREST API
Endpoint typeRegional

Create Resources and Methods

Endpoints:

MethodPathDescription
POST/writing/evaluateSubmit writing sample
POST/speaking/evaluateSubmit audio recording
POST/flashcards/generateGenerate flashcard
POST/upload/audioUpload audio
POST/upload/documentUpload document

API setup

Configure SQS Integration

For each POST endpoint, configure SQS integration:

  1. Select method → Integration Request
  2. Integration type: AWS Service
  3. AWS Service: SQS
  4. HTTP method: POST
  5. Action: SendMessage
  6. Execution role: API Gateway role with SQS permissions

Request Mapping Template:

Action=SendMessage&MessageBody=$util.urlEncode($input.body)&QueueUrl=$util.urlEncode('https://sqs.ap-southeast-1.amazonaws.com/{account}/ielts-writing-queue')

Enable CORS

  1. Select resource → Enable CORS
  2. Access-Control-Allow-Origin: * (or specific domain)
  3. Access-Control-Allow-Methods: POST, GET, OPTIONS

Deploy API

  1. ActionsDeploy API
  2. Stage name: dev
  3. Note the invoke URL: https://{api-id}.execute-api.ap-southeast-1.amazonaws.com/dev

AWS CLI Commands

# Create REST API
API_ID=$(aws apigateway create-rest-api \
    --name ielts-ai-api \
    --endpoint-configuration types=REGIONAL \
    --query 'id' --output text)

# Get root resource
ROOT_ID=$(aws apigateway get-resources \
    --rest-api-id $API_ID \
    --query 'items[?path==`/`].id' --output text)

# Create /ai resource
AI_RESOURCE=$(aws apigateway create-resource \
    --rest-api-id $API_ID \
    --parent-id $ROOT_ID \
    --path-part ai \
    --query 'id' --output text)

# Create /ai/writing-assessment resource
aws apigateway create-resource \
    --rest-api-id $API_ID \
    --parent-id $AI_RESOURCE \
    --path-part writing-assessment

Next Steps

Proceed to SQS Queues.