Skip to content
Pablo Rodriguez

Extending Serverless Api Gateway

Extending Serverless Architectures with Amazon API Gateway

Section titled “Extending Serverless Architectures with Amazon API Gateway”
  • Language Bridge: Connect software applications written in different languages in standardized way
  • Complexity Hiding: Hide implementation complexity from client applications
  • Documentation: Provide clear documentation on API usage and request formatting
  • Format Independence: Client applications don’t need to understand microservice technical details

APIs provide essential protection for rapidly scaling microservices:

  • Authorization: Choose whether to require authorization for access
  • Request Validation: Check request formats and return errors for incorrect formats
  • Throttling: Control the number of requests to prevent resource saturation
  • Access Control: Restrict resource access to allow only limited actions
  • Usage Tracking: Collect client usage data points for analysis
  • Billing Integration: Track usage for billing purposes
  • Statistics: Supply detailed usage statistics per client
  • Prioritization: Enable preferential usage for paying customers
  • API Types: Create, publish, and maintain REST, HTTP, and WebSocket APIs
  • Traffic Management: Configurable traffic management, authorization, and resource access control
  • Service Integration: Access to AWS services and publicly accessible endpoints
  • Version Management: Host multiple versions and stages of application APIs
  • Monetization: Establish client usage plans to control and monetize APIs
  • Performance: Cache common responses to improve latency
  • AWS Lambda: Direct integration for serverless compute
  • Amazon EC2: Applications running on EC2 instances
  • Amazon ECS: Containerized applications
  • Private Applications: VPC or on-premises applications
  • Public Endpoints: Publicly accessible HTTP endpoints
  • Direct AWS Services: Kinesis, Step Functions, DynamoDB
  • Concurrent Requests: Handle hundreds of thousands of concurrent API requests
  • Authorization Integration: Amazon Cognito integration and Lambda authorizer plugins
  • Development Environments: Multiple stages for development, testing, and production
  • Usage Plans: Third-party developer plans with throttling and quota limits
  • API Keys: Extract utilization data per API key for billing and analysis

Features:

  • Collection of routes and methods
  • Extensive API management features
  • Usage plans and payload validation
  • Private API endpoints and resource policies
  • Cross-origin resource sharing (CORS) support
  • Stateless architecture

Use Cases:

  • Applications requiring comprehensive API management
  • Need for usage plans, billing, and access control
  • Private API endpoints in VPC
  • Resource-based security policies
  • HTTP Methods: GET, POST, PUT, PATCH, DELETE for CRUD operations
  • Stateless Design: Smooth redeployment and scaling for cloud applications
  • Example: POST /class-roster (add student), GET /class-roster (retrieve all students)

Performance HTTP APIs provide up to 70% cost reduction and improved performance over REST APIs for simple proxy use cases.

Standard microservice pattern using:

  • Amazon Cognito for authorization
  • API Gateway for request routing
  • AWS Lambda for business logic
  • Amazon DynamoDB for data storage
  • Public Endpoints: Connect API routes to publicly routable HTTP endpoints
  • Request/Response Flow: API Gateway passes entire request and response between frontend and backend
  • Configuration: Simply provide URL of publicly routable HTTP endpoint

Direct connections to AWS service APIs:

  • Amazon SQS: Send messages to queues
  • AWS Step Functions: Start state machine executions
  • Amazon DynamoDB: Direct database operations
  • Benefits: Bypass Lambda for simple AWS service calls
  • REST APIs: Access Network Load Balancer in VPC
  • HTTP APIs: Access Network Load Balancer, Application Load Balancer, and other VPC services
  • Use Cases: Amazon EC2 instances, Amazon ECS containers, private applications

Activity: Decomposing Monolithic Application

Section titled “Activity: Decomposing Monolithic Application”

Monolithic Shopping Application Components

Section titled “Monolithic Shopping Application Components”

Original monolithic application includes:

  • Shopping Cart: Add, remove, update items with single-digit second response time
  • Payments: Finalize cart and process payments (port as-is with minimal changes)
  • Delivery: Multi-day process with customer notifications

Solution: Amazon API Gateway HTTP API + AWS Lambda + Amazon DynamoDB

  • Performance: Millisecond transactions meeting single-digit response requirements
  • Architecture: HTTP API routes requests to Lambda function
  • Data Storage: DynamoDB shopping cart table
  • Benefit: Scales automatically and provides fast response times

Solution: Amazon API Gateway HTTP API + Application Load Balancer + Amazon ECS + DynamoDB

  • Legacy Compatibility: ECS containers allow minimal code changes from on-premises
  • Load Distribution: Application Load Balancer distributes payment transactions
  • External Integration: Containers access publicly accessible banking APIs
  • Data Storage: DynamoDB payment table
  • Benefit: Preserves existing payment logic while enabling cloud scalability

Solution: Amazon API Gateway HTTP API + AWS Step Functions + Amazon SQS + Amazon SNS + DynamoDB

Important This is a workflow service, not a microservice, due to multi-day duration.

Workflow Process:

  1. Initiation: API Gateway receives delivery call, forwards to Step Functions
  2. Queue Processing: State machine puts request on SQS delivery queue and suspends
  3. External Processing: Inventory/delivery API polls queue and processes delivery
  4. Callback: Upon completion, API callbacks to state machine
  5. Decision Logic: Choice state determines if order delivered or cancelled
  6. Notifications: Amazon SNS sends email notifications to customers
  7. Cleanup: If cancelled, refund request placed on SQS refund queue

Benefits: Handles long-running processes with proper state management, error handling, and customer communication.

Amazon API Gateway provides comprehensive API creation and management capabilities with multiple API types suited for different use cases. REST APIs offer full management features, HTTP APIs provide optimized performance for microservices, and WebSocket APIs enable real-time applications requiring active sessions.