Building a Zero-Trust Microservice Architecture on AWS: Combining VPC Lattice, IAM, and Amazon Cognito
Traditional perimeter-based security—the classic "hard outer shell, soft inner core" model—is no longer sufficient for modern cloud applications. Once a malicious actor or compromised service gets inside your Virtual Private Cloud (VPC), flat network designs often allow unrestricted lateral movement.
A Zero-Trust architecture operates on a simple principle: Never trust, always verify. Every request, whether originating from outside the network or between two internal microservices, must be explicitly authenticated, authorized, and encrypted.Historically, implementing Zero-Trust across multiple AWS accounts and VPCs required complex VPC Peering, Transit Gateways, Mutual TLS (mTLS) certificates, and custom sidecar proxies. Amazon VPC Lattice simplifies this by managing service-to-service networking, security, and observability at the application layer.In this guide, we will build a Zero-Trust microservice architecture using Amazon VPC Lattice, AWS IAM, and Amazon Cognito.Architecture OverviewHere is the high-level flow of our end-to-end Zero-Trust design:User Authentication: An end-user authenticates against an Amazon Cognito User Pool and receives a JSON Web Token (JWT).Ingress Authorization: The user calls the API Gateway / Ingress Service, passing the JWT in the Authorization header.Service Network Transport: The Ingress Service processes the request and needs to call an internal downstream microservice (hosted on AWS Lambda or ECS).Service-to-Service IAM Auth: The calling service signs its HTTP request to the VPC Lattice service endpoint using AWS Signature Version 4 (SigV4).Zero-Trust Verification: VPC Lattice evaluates the attached IAM Auth Policy. If authorized, it routes the traffic securely across VPC boundaries to the target microservice.+------------------+ JWT Token +-----------------------+
| Client / App | ------------------------> | Amazon Cognito Pool |
+------------------+ +-----------------------+
|
| 1. Request with JWT
v
+----------------------------------------------------------------------+
| VPC A: Public/Ingress Layer |
| +----------------------------------------------------------------+ |
| | Ingress Microservice (ECS / Lambda) | |
| +----------------------------------------------------------------+ |
+----------------------------------------------------------------------+
|
| 2. SigV4 Signed Request
v
+----------------------------------------------------------------------+
| AWS VPC Lattice Service Network |
| - Enforces IAM Auth Policy (Service-to-Service) |
| - Encrypts TLS in transit |
+----------------------------------------------------------------------+
|
| 3. Routed & Authorized Traffic
v
+----------------------------------------------------------------------+
| VPC B: Internal Service Layer |
| +----------------------------------------------------------------+ |
| | Payment / Core Microservice (Target Group) | |
| +----------------------------------------------------------------+ |
+----------------------------------------------------------------------+
Step 1: User Authentication with Amazon CognitoTo secure the front door of your application, use Amazon Cognito to issue identity tokens to authenticated users.1. Configure the Cognito User PoolSet up a Cognito User Pool with app clients configured for your frontend/mobile application.2. Verify Incoming JWTs at the Ingress LayerWhen the Ingress microservice receives a request, it validates the incoming Cognito JWT against the User Pool's JSON Web Key Set (JWKS).Here is a Node.js snippet using aws-jwt-verify to enforce user identity check before proceeding:JavaScriptimport { CognitoJwtVerifier } from "aws-jwt-verify";
const verifier = CognitoJwtVerifier.create({
userPoolId: "us-east-1_ExamplePoolId",
tokenUse: "access",
clientId: "2uexampleclientid123456789",
});
export async function authorizeUser(authHeader) {
const token = authHeader.replace("Bearer ", "");
try {
const payload = await verifier.verify(token);
console.log("Token is valid for user:", payload.sub);
return payload;
} catch (err) {
throw new Error("Unauthorized: Invalid Cognito Token");
}
}
Step 2: Creating the VPC Lattice Service NetworkVPC Lattice introduces three core constructs:Service Network: A logical boundary that connects services across VPCs and accounts.Service: Your microservice (e.g., Payment Service) registered with a domain, routing rules, and target groups.Auth Policy: An IAM policy attached directly to the Service or Service Network to control access.1. Define the Lattice Service NetworkUsing the AWS CLI, create your service network:Bashaws vpc-lattice create-service-network
--name microservices-zero-trust-network
--auth-type AWS_IAM
2. Associate Your VPCsAssociate the VPC hosting your Ingress service and the VPC hosting your internal services with this Service Network.Step 3: Enforcing IAM Authentication on Service-to-Service CallsInstead of relying on broad IP ranges or open Security Groups, VPC Lattice allows you to enforce AWS IAM Authorization (AWS_IAM) on every HTTP/HTTPS route.1. Attach an Auth Policy to the ServiceThe following policy ensures that only the IAM Role used by the Ingress service (IngressServiceRole) can call the internal Payment Service:JSON{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/IngressServiceRole"
},
"Action": "vpc-lattice-svcs:Invoke",
"Resource": "arn:aws:vpc-lattice:us-east-1:123456789012:service/svc-0123456789abcdef0",
"Condition": {
"StringEquals": {
"vpc-lattice-svcs:RequestMethod": "POST"
}
}
}
]
}
2. Sign Internal Requests with SigV4When the Ingress service sends an HTTP request to the internal Payment Service's Lattice URL, it must sign the request using standard AWS Signature Version 4 (SigV4).Here is how to implement this in Python using requests and aws-requests-auth:Pythonimport requests
from aws_requests_auth.aws_auth import AWSRequestsAuth
Configure SigV4 signing using ambient IAM execution role credentials
auth = AWSRequestsAuth(
aws_access_key='YOUR_TEMP_ACCESS_KEY',
aws_secret_access_key='YOUR_TEMP_SECRET_KEY',
aws_token='YOUR_TEMP_SESSION_TOKEN',
aws_host='payment-service-0123456789.vpc-lattice-svcs.us-east-1.on.aws',
aws_region='us-east-1',
aws_service='vpc-lattice-svcs'
)
Make authenticated cross-service call over VPC Lattice
response = requests.post(
' https://payment-service-0123456789.vpc-lattice-svcs.us-east-1.on.aws/process ',
json={'order_id': '98765', 'amount': 49.99},
auth=auth
)
print(f"Response Status: {response.status_code}")
print(f"Response Body: {response.text}")
Step 4: End-to-End Verification and ObservabilityWith this architecture in place, every request undergoes two distinct verification checkpoints:LayerComponentAuthentication MechanismScopeUser AccessAmazon CognitoOAuth2 / OIDC JWTVerifies human user identity & application contextService-to-ServiceAWS VPC LatticeIAM SigV4Verifies machine workload identity & least-privilege permissionsObservability BenefitsBecause VPC Lattice acts as an application-level proxy, you can send access logs directly to Amazon CloudWatch Logs, Amazon S3, or Amazon Kinesis Data Firehose.Each log entry records:Source IAM Principal ARNTarget Service ARNHTTP Method, Path, and Response CodeTLS cipher and verification statusThis provides complete, central auditability for every request across your enterprise network.ConclusionCombining Amazon Cognito for end-user auth and AWS VPC Lattice + IAM for internal microservice communication gives you a robust, production-ready Zero-Trust Architecture:Network perimeters become secondary; explicit identity validation happens at every hop.Cross-VPC networking is drastically simplified—no IP address overlap issues or complex routing tables.Least-privilege access is enforced at the HTTP method and path level using native IAM policies.By leveraging AWS VPC Lattice, you can transition away from legacy perimeter security and adopt true Zero-Trust microservices without adding operational overhead or proxy management to your team.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article