Kanji
・Cloud engineer / freelance ・Born in 1993 ・From Ehime / Living in Shibuya, Tokyo ・5 years AWS experience Profile details
Table of Contents
botocore
curl
When conducting PoCs to connect autonomous AI coding agents (such as Antigravity, Claude Code, and Amazon Bedrock AgentCore) directly to internal databases and microservices, I immediately ran into a fundamental architectural challenge: how to securely enforce boundaries between non-deterministic AI agents and private backend workloads .
In traditional AWS multi-account and multi-VPC architectures, access control has almost universally relied on Layer 3 and Layer 4 network boundaries:
However, the moment an autonomous AI agent capable of generating code and executing tools is placed into this environment, a serious vulnerability emerges.
[ Autonomous AI Agent (EC2 / ECS / AgentCore) ] │ ▼ (L3/L4 Traffic Allowed: Reaching destination at IP/Port level) [ Internal Core API Server (ALB + Private ECS) ] ├── GET /api/v1/customers/search (Intended safe read-only operation) ├── POST /api/v1/customers/update (Unintended data modification risk) └── DELETE /api/v1/customers/purge (Catastrophic data deletion risk)
If an AI agent misunderstands a prompt, hallucinates tool parameters, or falls victim to an indirect prompt injection attack, it might execute an unintended DELETE /api/v1/customers/purge request. Because IP addresses and port 443 are fully permitted by security groups, the network layer will never stop it.
DELETE /api/v1/customers/purge
The foundational assumption of perimeter security—that “traffic within the private VPC is trusted”—completely falls apart when applied to AI agents with unpredictable operational autonomy.
I needed an architecture that ignores static IP routing and cryptographically inspects every single HTTP request at Layer 7: Which IAM principal is sending this request, and is it authorized for this specific HTTP method and path?
The solution that cleanly resolved this challenge was combining Amazon VPC Lattice with AWS IAM SigV4 (Signature Version 4) authentication.
▲ Overall architecture: Enforcing Layer 7 least-privilege authorization for AI agents using Amazon VPC Lattice Service Networks, Services, and IAM SigV4 authentication
Amazon VPC Lattice is a fully managed application-layer (Layer 7) networking service.
Unlike traditional Transit Gateway setups or PrivateLink endpoints, it completely removes the need for complex CIDR planning, routing table meshing, or overlapping IP resolution . More importantly, it natively enforces AWS IAM cryptographic signatures (SigV4) at the individual HTTP request level .
When a Service in VPC Lattice is configured with authType = AWS_IAM , every incoming HTTP/HTTPS request must carry valid SigV4 signature headers ( Authorization: AWS4-HMAC-SHA256 ... ).
authType = AWS_IAM
Authorization: AWS4-HMAC-SHA256 ...
Any unsigned request, or any request from an IAM role not explicitly permitted by policy, is immediately rejected with an HTTP 403 Forbidden ( AccessDeniedException ) by the Lattice fabric before reaching backend services .
AccessDeniedException
The most critical architectural concept in VPC Lattice is the two-tier Auth Policy evaluation model (logical AND condition) applied across the Service Network and individual Services.
For any request to succeed, it must be explicitly permitted by both policies simultaneously:
[ Calling AI Agent ] │ (HTTP Request signed with AWS SigV4) ▼ [ Tier 1 Evaluation ] Service Network Auth Policy ──> [ Org Guardrails: Allow? ] │ (Yes) ▼ [ Tier 2 Evaluation ] Service Auth Policy ──> [ Method/Path Least Privilege: Allow? ] │ (Yes) ▼ [ Backend Target Group (Private ECS / ALB) ]
At the Service Network level, platform administrators can enforce enterprise-wide guardrails: ensuring that only principals belonging to the trusted AWS Organization can initiate calls, and blocking anonymous requests.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforceOrgBoundaryAndSigV4", "Effect": "Allow", "Principal": "*", "Action": "vpc-lattice-svcs:Invoke", "Resource": "*", "Condition": { "StringNotEqualsIgnoreCase": { "aws:PrincipalType": "Anonymous" }, "StringEquals": { "aws:PrincipalOrgID": "o-xxxxxxxxxx" } } } ] }
This single policy guarantees that requests from unauthorized accounts or unsigned probes are dropped at the network perimeter.
At the individual Service level (e.g., an internal customer database service), application developers attach a fine-grained policy that restricts callers to specific IAM roles, HTTP verbs ( vpc-lattice-svcs:RequestMethod ), URL paths ( vpc-lattice-svcs:RequestPath ), source VPCs ( vpc-lattice-svcs:SourceVpc ), or custom headers ( vpc-lattice-svcs:RequestHeader/${HeaderName} ):
vpc-lattice-svcs:RequestMethod
vpc-lattice-svcs:RequestPath
vpc-lattice-svcs:SourceVpc
vpc-lattice-svcs:RequestHeader/${HeaderName}
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowOnlyAgentReadOnlySearch", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/ResearchAgentExecutionRole" }, "Action": "vpc-lattice-svcs:Invoke", "Resource": "*", "Condition": { "StringEquals": { "vpc-lattice-svcs:RequestMethod": "GET", "vpc-lattice-svcs:SourceVpc": "vpc-0a1b2c3d4e5f6g7h8" }, "StringLike": { "vpc-lattice-svcs:RequestPath": "/api/v1/customers/search*" } } } ] }
Even if the research agent attempts a POST /api/v1/customers or a DELETE call due to hallucinated tool logic, VPC Lattice rejects the call at Layer 7 before a single byte reaches the backend application .
POST /api/v1/customers
DELETE
When authType = AWS_IAM is enabled, plain curl commands and standard HTTP libraries will instantly fail.
Here is the exact terminal output when sending an unsigned request to our test service:
# Executing plain curl against VPC Lattice service endpoint $ curl -i https://customer-search-service-0a1b2c3d4e5f.7g8h9i.vpc-lattice-svcs.ap-northeast-1.on.aws/api/v1/customers/search HTTP/2 403 date: Wed, 26 Nov 2026 06:15:20 GMT content-type: application/json content-length: 98 x-amzn-errortype: AccessDeniedException {"message":"Access denied: Request is missing required AWS Signature Version 4 authentication."}
Without valid cryptographic headers, the request is shut down immediately.
To enable AI agents running Python scripts to query Lattice services transparently, we built a lightweight wrapper using botocore.auth.SigV4Auth :
botocore.auth.SigV4Auth
import os import requests from botocore.auth import SigV4Auth from botocore.awsrequest import AWSRequest from botocore.session import Session class VPCLatticeSigV4Client: def __init__(self, region_name: str = "ap-northeast-1"): self.session = Session() self.credentials = self.session.get_credentials() self.region_name = region_name self.service_name = "vpc-lattice-svcs" def request(self, method: str, url: str, headers: dict = None, data: str = None): headers = headers or {} from urllib.parse import urlparse parsed = urlparse(url) headers["Host"] = parsed.netloc aws_request = AWSRequest( method=method.upper(), url=url, headers=headers, data=data ) auth = SigV4Auth(self.credentials, self.service_name, self.region_name) auth.add_auth(aws_request) response = requests.request( method=method.upper(), url=url, headers=dict(aws_request.headers), data=data, timeout=10.0 ) return response if __name__ == "__main__": client = VPCLatticeSigV4Client() endpoint = "https://customer-search-service-0a1b2c3d4e5f.7g8h9i.vpc-lattice-svcs.ap-northeast-1.on.aws/api/v1/customers/search?query=test" print("[*] Sending SigV4 signed GET request to VPC Lattice...") res = client.request("GET", endpoint) print(f"[*] Response Status Code: {res.status_code}") print(f"[*] Response Body: {res.text[:200]}")
▲ Real terminal verification: Instant 403 rejection on unsigned requests vs. clean 200 OK response upon injecting SigV4 headers
To ensure consistency across environments, we codified the entire Lattice topology using Terraform:
# 1. Organization-wide Service Network resource "aws_vpclattice_service_network" "ai_core" { name = "ai-agent-core-network" auth_type = "AWS_IAM" } # 2. Service Network Auth Policy (Organizational Guardrail) resource "aws_vpclattice_auth_policy" "network_policy" { resource_identifier = aws_vpclattice_service_network.ai_core.arn policy = jsonencode({ Version = "2012-10-17" Statement = [ { Sid = "OrgBoundaryGuardrail" Effect = "Allow" Principal = "*" Action = "vpc-lattice-svcs:Invoke" Resource = "*" Condition = { StringNotEqualsIgnoreCase = { "aws:PrincipalType" = "Anonymous" } StringEquals = { "aws:PrincipalOrgID" = var.aws_org_id } } } ] }) } # 3. Lattice Service Definition resource "aws_vpclattice_service" "customer_search" { name = "customer-search-service" auth_type = "AWS_IAM" } # 4. Associate Service with Service Network resource "aws_vpclattice_service_network_service_association" "search_assoc" { service_identifier = aws_vpclattice_service.customer_search.id service_network_identifier = aws_vpclattice_service_network.ai_core.id } # 5. Service-Level Auth Policy (Granular Least Privilege) resource "aws_vpclattice_auth_policy" "service_policy" { resource_identifier = aws_vpclattice_service.customer_search.arn policy = jsonencode({ Version = "2012-10-17" Statement = [ { Sid = "ReadOnlyAgentSearchOnly" Effect = "Allow" Principal = { AWS = var.agent_role_arn } Action = "vpc-lattice-svcs:Invoke" Resource = "*" Condition = { StringEquals = { "vpc-lattice-svcs:RequestMethod" = "GET" "vpc-lattice-svcs:SourceVpc" = var.agent_vpc_id } StringLike = { "vpc-lattice-svcs:RequestPath" = "/api/v1/customers/search*" } } } ] }) }
▲ AWS Management Console: Service Network detail view displaying Auth Type set to AWS_IAM with active Auth Policies
During our hands-on deployment, we encountered two subtle pitfalls worth documenting.
A common misconception is that defining an Allow rule inside the VPC Lattice Auth Policy is sufficient. However, the calling IAM principal must also have explicit permissions in its own identity-based policy to invoke Lattice services:
Allow
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowLatticeInvoke", "Effect": "Allow", "Action": "vpc-lattice-svcs:Invoke", "Resource": "arn:aws:vpc-lattice:ap-northeast-1:123456789012:service/*" } ] }
Without this identity-based permission, requests will still be denied with AccessDeniedException .
During local testing on Docker or WSL2 environments after waking from sleep, requests were repeatedly rejected with Signature expired . AWS SigV4 strictly requires that client clocks differ by no more than 5 minutes from AWS server clocks. Ensure NTP synchronization ( chrony or systemd-timesyncd ) is active in all agent execution containers.
Signature expired
chrony
systemd-timesyncd
We measured round-trip latency over 1,000 requests between an ECS agent container and a backend private service in the Tokyo region ( ap-northeast-1 ):
ap-northeast-1
The cryptographic signature generation and two-tier policy evaluation add approximately +3.5 ms of overhead . Compared to AI model inference latency (typically several hundred milliseconds to seconds), this network overhead is virtually negligible.
Amazon VPC Lattice Pricing & Cost Efficiency : VPC Lattice pricing consists of three dimensions: (1) Provisioned service hours ($0.025/service-hour, approx. $18.25/month), (2) Data processing ($0.025/GB with no additional cross-AZ data transfer fees), and (3) HTTP/HTTPS request fees ($0.10 per million requests, with the first 300,000 requests per hour per service free ). For internal AI agent tool invocations, request charges typically stay well within the hourly free tier.
Relying solely on system prompts or application-level if statements to restrict autonomous AI agents is inherently risky.
if
By architecting access via Amazon VPC Lattice and IAM SigV4 : - Even if an agent malfunctions or is manipulated via prompt injection, disallowed paths and methods are physically blocked at Layer 7. - Cross-account connectivity is decoupled from fragile IP routing and VPC peering meshes. - AWS CloudTrail captures an immutable, principal-level audit log of every single request made by an AI agent.
This architecture provides the safety net needed to deploy autonomous agents with confidence, ensuring enterprise workloads remain protected without stifling agent utility.
Real-time AI quant analysis of earnings reports, corporate filings, and momentum indicators for global equities and Japanese stocks.
Master conversation skills with realistic AI phone training and 5-axis feedback. Includes 16-lesson interactive academy and studio AI portraits.
Effortlessly snap receipts for instant AI itemization. Integrated with LINE for seamless group expense tracking and pain-free settlement.
Interactive AI personas (Fortune Teller, Butler, Bartender) host real-time games, challenges, and conversation starters for unforgettable gatherings.
Unbiased healthcare database featuring zero-additive filters and active ingredient cost performance metrics.