I am creating a design for my eCommerce application. It will have multiple services backed by AWS Lambdas. Orderservice, InventoryService, PaymentService, LoggingService, dashboardService are some of those services. I cannot give the exact number of services but it will surely be more than 15. As per this link microservices , a good microservices architecture should have one gateway that will route to the corresponding services. The code for my AWS ApiGateway with order Lambda function looks like below.
My question is that each of Orderservice, inventoryservice, paymentservice etc can have multiple routes for get, post, delete, put. Most of them will have nested resources. In this situation should I include api routes and lambda functions for all these services within the same SAM template. If yes, wouldn't it be a monolith Template. If I need to change in any service, I have to deploy the whole template and breaks the microservice principles. Ideally, I want to deploy all these services independently and yet share the ApiGateway. Is this possible ?. If not, should I create separate ApiGateway for each service in different SAM template so they can be deployed separately. This will cause authentication, authorisation, monitoring be repeated in all gateways which again doesn't sound like way to go.
Please suggest what is the right way to do this.
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: ApiGateway for the Ecommerce
Resources:
EcomApi:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
swagger: "2.0"
info:
title: Ecommerce Api
schemes:
- "https"
x-amazon-apigateway-request-validator: Validate body and params
paths:
/order:
get:
summary: Get the orders
consumes:
- "application/json"
produces:
- "application/json"
responses:
"200":
description: "200 response"
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: "string"
security:
- Auth: []
x-amazon-apigateway-integration:
type: "AWS_PROXY"
httpMethod: "POST"
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetOrders.Arn}/invocations
responses:
default:
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Origin: "'*'"
passthroughBehavior: "when_no_match"
contentHandling: "CONVERT_TO_TEXT"
GetOrders:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: src/handlers/getOrders.handler
Role:
Fn::GetAtt:
- TestRole
- Arn
Events:
List:
Type: Api
Properties:
Path: /orders
Method: get
RestApiId: !Ref EcomApi