VPC Lattice
Amazon VPC Lattice is an AWS application networking service that allows you to securely connect and manage services across different VPCs and accounts. This document explains the concepts, architecture, integration methods with Amazon EKS, and best practices for VPC Lattice.
Table of Contents
- Overview
- Architecture
- EKS and VPC Lattice Integration
- Installation and Configuration
- Service Management
- Routing and Traffic Management
- Security and Authentication
- Monitoring and Logging
- Best Practices
- Troubleshooting
- Conclusion
Overview
What is VPC Lattice?
Amazon VPC Lattice is a fully managed application networking service for service-to-service connectivity, security, and monitoring. Key features include:
- Service Network: A logical boundary that connects services across multiple VPCs and accounts
- Service Discovery: Automatic discovery of services within the service network
- Traffic Management: Support for routing rules, weighted routing, and path-based routing
- Authentication and Authorization: Access control through AWS IAM and resource policies
- Observability: Integrated monitoring, logging, and tracing capabilities
Key Use Cases
- Microservices Architecture: Simplify and secure communication between microservices
- Multi-Account Environments: Secure communication between services across multiple AWS accounts
- Hybrid Workloads: Communication between containerized and non-containerized workloads
- Service Mesh Alternative: Provide lightweight service mesh functionality to reduce complexity
- Multi-Cluster Connectivity: Simplify service communication between multiple EKS clusters
VPC Lattice vs Other Services
VPC Lattice vs API Gateway
| Feature | VPC Lattice | API Gateway |
|---|---|---|
| Primary Use | Internal service-to-service communication | External API exposure |
| Network Location | Inside VPC | Internet-connected |
| Protocols | HTTP/HTTPS, gRPC | HTTP/HTTPS, WebSocket, REST, GraphQL |
| Authentication | AWS IAM, resource policies | IAM, Lambda authorizers, Cognito |
| Scalability | Auto-scaling | Auto-scaling |
| Pricing | Hourly + data throughput | Request count + data throughput |
VPC Lattice vs AWS App Mesh
| Feature | VPC Lattice | AWS App Mesh |
|---|---|---|
| Architecture | Managed service | Sidecar proxy-based |
| Complexity | Low | Medium |
| Protocols | HTTP/HTTPS, gRPC | HTTP/HTTPS, gRPC, TCP |
| Service Discovery | Built-in | AWS Cloud Map integration |
| Traffic Control | Basic routing rules | Advanced traffic control |
| Observability | CloudWatch integration | Detailed metrics via Envoy |
VPC Lattice vs Transit Gateway
| Feature | VPC Lattice | Transit Gateway |
|---|---|---|
| Primary Use | Service-to-service communication | VPC-to-VPC network connectivity |
| Abstraction Level | Service level | Network level |
| Protocol | Application layer (L7) | Network layer (L3) |
| Routing | Service name-based | IP-based |
| Security | Service-level policies | Security groups, NACLs |
Architecture
VPC Lattice Components
VPC Lattice consists of the following main components:
- Service Network: A logical boundary for service-to-service communication
- Service: An endpoint representing an application or microservice
- Target Group: A set of targets to route traffic to a service
- Listener: A process that handles connection requests to a service
- Rule: Defines how a listener routes traffic
- VPC Association: Connects a VPC to a service network
Service Network Architecture
The service network is a core component of VPC Lattice that connects services across multiple VPCs and accounts.
Traffic Flow
How traffic flows in VPC Lattice:
- Client sends a request to the VPC Lattice service DNS name
- VPC Lattice receives the request and processes it according to listener rules
- Listener rules route the request to the appropriate target group
- Target group forwards the request to registered targets (EC2, EKS pods, Lambda, etc.)
- Target processes the response and returns it to the client
Service Discovery
VPC Lattice automatically provides service discovery within the service network:
- Each service has a unique DNS name (
service-name.vpc-lattice-svcs.region.on.aws) - Clients access services using this DNS name
- VPC Lattice handles DNS resolution and routing
- Services are accessible from all VPCs connected to the service network
Security Model
VPC Lattice provides the following security mechanisms:
- Network Isolation: Service network provides a logically isolated environment
- Authentication and Authorization: Service access control through AWS IAM
- Resource Policies: Fine-grained access control for services and service networks
- TLS Encryption: Encryption of service-to-service communication
- VPC Security Groups: Additional security layer for targets
EKS and VPC Lattice Integration
Integration Architecture
The integration of Amazon EKS and VPC Lattice consists of the following components:
- AWS Gateway API Controller: Transforms Kubernetes Gateway API into VPC Lattice resources
- Kubernetes Gateway API: Standard Kubernetes API for service routing
- VPC Lattice Service Network: Service network to which EKS clusters connect
- VPC Lattice Service: VPC Lattice services mapped to Kubernetes services
- VPC Lattice Target Group: Target groups mapped to Kubernetes pods
Benefits of Integration
Integrating EKS with VPC Lattice provides the following benefits:
- Standardized API: Consistent service management through Kubernetes Gateway API
- Cross-Cluster Communication: Seamless communication between multiple EKS clusters
- Hybrid Workloads: Communication between EKS pods and non-containerized workloads
- Centralized Management: Manage all service networks from AWS console
- Unified Observability: Integrated monitoring and logging through CloudWatch and CloudTrail
- Simplified Service Mesh: Provide service mesh functionality without sidecars
VPC Lattice as a Service Mesh Alternative
VPC Lattice can be an alternative to traditional service meshes (Istio, Linkerd, etc.) for the following reasons:
- Low Complexity: Provides service mesh functionality without sidecar proxies
- Reduced Management Overhead: Fully managed service by AWS
- Resource Efficiency: Reduced resource usage without sidecar proxies
- AWS Service Integration: Seamless integration with AWS service ecosystem
| Feature | VPC Lattice | Traditional Service Mesh |
|---|---|---|
| Service Discovery | Built-in | Requires separate configuration |
| Traffic Routing | Supported | Supported |
| Traffic Splitting | Supported | Supported |
| Detailed Traffic Control | Limited | Extensive |
| Sidecar Proxy | Not required | Required |
| Management Complexity | Low | High |
| Resource Overhead | Low | High |
| Observability | CloudWatch integration | Various tool support |
Installation and Configuration
Prerequisites
Prerequisites for integrating VPC Lattice with EKS:
- Amazon EKS Cluster: Kubernetes version 1.23 or higher
- IAM Permissions: Permissions to create and manage VPC Lattice resources
- VPC Setup: VPC with private subnets
- AWS CLI: Latest version of AWS CLI
- kubectl: Latest version of kubectl
- Helm: (Optional) Helm 3 for AWS Gateway API Controller installation
Installing AWS Gateway API Controller
AWS Gateway API Controller is responsible for transforming Kubernetes Gateway API resources into VPC Lattice resources.
Installation Using Helm
# Add Helm repository
helm repo add eks https://aws.github.io/eks-charts
helm repo update
# Install AWS Gateway API Controller
helm install gateway-api-controller eks/aws-gateway-controller \
--namespace aws-gateway-controller \
--create-namespace \
--set serviceAccount.create=true \
--set serviceAccount.name=aws-gateway-controller \
--set serviceAccount.annotations."eks\.amazonaws\.com/role-arn"=arn:aws:iam::<AWS_ACCOUNT_ID>:role/AmazonGatewayControllerRoleInstallation Using YAML Manifests
- Service account and RBAC setup:
apiVersion: v1
kind: ServiceAccount
metadata:
name: aws-gateway-controller
namespace: aws-gateway-controller
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::<AWS_ACCOUNT_ID>:role/AmazonGatewayControllerRole
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: aws-gateway-controller
rules:
- apiGroups: ["gateway.networking.k8s.io"]
resources: ["gatewayclasses", "gateways", "httproutes"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
resources: ["services", "secrets", "namespaces"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: aws-gateway-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: aws-gateway-controller
subjects:
- kind: ServiceAccount
name: aws-gateway-controller
namespace: aws-gateway-controller- Controller deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: aws-gateway-controller
namespace: aws-gateway-controller
spec:
replicas: 1
selector:
matchLabels:
app: aws-gateway-controller
template:
metadata:
labels:
app: aws-gateway-controller
spec:
serviceAccountName: aws-gateway-controller
containers:
- name: controller
image: public.ecr.aws/aws-application-networking-k8s/aws-gateway-controller:v1.0.0
args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=:8080
- --leader-elect
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 10m
memory: 64MiIAM Role Setup
The AWS Gateway API Controller requires appropriate IAM permissions to manage VPC Lattice resources.
IRSA (IAM Roles for Service Accounts) Setup
# Create IAM policy
cat <<EOF > vpc-lattice-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"vpc-lattice:*",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeSecurityGroups",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:DescribeTargetHealth",
"elasticloadbalancing:RegisterTargets",
"elasticloadbalancing:DeregisterTargets"
],
"Resource": "*"
}
]
}
EOF
aws iam create-policy \
--policy-name AmazonGatewayControllerPolicy \
--policy-document file://vpc-lattice-policy.json
# Create IAM role and associate with service account
eksctl create iamserviceaccount \
--name aws-gateway-controller \
--namespace aws-gateway-controller \
--cluster <CLUSTER_NAME> \
--attach-policy-arn arn:aws:iam::<AWS_ACCOUNT_ID>:policy/AmazonGatewayControllerPolicy \
--approve \
--override-existing-serviceaccountsCreating VPC Lattice Service Network
VPC Lattice service networks can be created through AWS Management Console, AWS CLI, or AWS CloudFormation.
Creation Using AWS CLI
# Create service network
aws vpc-lattice create-service-network \
--name my-service-network \
--auth-type AWS_IAM
# Store service network ID
SERVICE_NETWORK_ID=$(aws vpc-lattice list-service-networks \
--query "items[?name=='my-service-network'].id" \
--output text)
# Associate VPC with service network
aws vpc-lattice create-service-network-vpc-association \
--service-network-identifier $SERVICE_NETWORK_ID \
--vpc-identifier <VPC_ID> \
--security-group-ids <SECURITY_GROUP_ID>Creation Using AWS CloudFormation
Resources:
MyServiceNetwork:
Type: AWS::VpcLattice::ServiceNetwork
Properties:
Name: my-service-network
AuthType: AWS_IAM
MyVpcAssociation:
Type: AWS::VpcLattice::ServiceNetworkVpcAssociation
Properties:
ServiceNetworkIdentifier: !Ref MyServiceNetwork
VpcIdentifier: !Ref MyVPC
SecurityGroupIds:
- !Ref MySecurityGroupConfiguring Gateway API Resources
Configure Kubernetes Gateway API resources to integrate with VPC Lattice.
1. Create GatewayClass
GatewayClass defines the implementation of Gateway resources.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: amazon-vpc-lattice
spec:
controllerName: application-networking.k8s.aws/gateway-api-controller2. Create Gateway
Gateway defines how traffic enters the cluster.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-gateway
namespace: default
annotations:
application-networking.k8s.aws/service-network-id: <SERVICE_NETWORK_ID>
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: http
port: 80
protocol: HTTP3. Create HTTPRoute
HTTPRoute defines how HTTP traffic is routed to services.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: my-http-route
namespace: default
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api
backendRefs:
- name: my-service
port: 8080Service and Pod Configuration
Configure Kubernetes services and pods to integrate with VPC Lattice.
1. Create Service
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: default
spec:
selector:
app: my-app
ports:
- port: 8080
targetPort: 8080
type: ClusterIP2. Create Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:latest
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10Service Management
Creating VPC Lattice Services
VPC Lattice services can be created directly through AWS Management Console, AWS CLI, or AWS CloudFormation, or indirectly through Kubernetes Gateway API.
Direct Creation Using AWS CLI
# Create target group
aws vpc-lattice create-target-group \
--name my-target-group \
--type INSTANCE \
--config '{"port":80,"protocol":"HTTP","vpcIdentifier":"<VPC_ID>","healthCheck":{"enabled":true,"protocol":"HTTP","path":"/health","port":80,"healthCheckIntervalSeconds":30,"healthCheckTimeoutSeconds":5,"healthyThresholdCount":5,"unhealthyThresholdCount":2}}'
# Store target group ID
TARGET_GROUP_ID=$(aws vpc-lattice list-target-groups \
--query "items[?name=='my-target-group'].id" \
--output text)
# Create service
aws vpc-lattice create-service \
--name my-service \
--auth-type AWS_IAM
# Store service ID
SERVICE_ID=$(aws vpc-lattice list-services \
--query "items[?name=='my-service'].id" \
--output text)
# Create listener
aws vpc-lattice create-listener \
--service-identifier $SERVICE_ID \
--name my-listener \
--protocol HTTP \
--port 80 \
--default-action '{"forward":{"targetGroups":[{"targetGroupIdentifier":"'$TARGET_GROUP_ID'"}]}}'
# Associate service with service network
aws vpc-lattice create-service-network-service-association \
--service-network-identifier $SERVICE_NETWORK_ID \
--service-identifier $SERVICE_IDIndirect Creation Using Kubernetes Gateway API
When you create Gateway API resources, the AWS Gateway API Controller automatically creates VPC Lattice resources.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-gateway
namespace: default
annotations:
application-networking.k8s.aws/service-network-id: <SERVICE_NETWORK_ID>
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: http
port: 80
protocol: HTTP
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: my-http-route
namespace: default
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api
backendRefs:
- name: my-service
port: 8080Service Discovery and Access
VPC Lattice services are automatically assigned DNS names and are discoverable within the service network.
DNS Name Format
<service-name>.<service-network-id>.vpc-lattice-svcs.<region>.on.awsService Access Example
# Query service DNS name
SERVICE_DNS=$(aws vpc-lattice get-service \
--service-identifier $SERVICE_ID \
--query "dnsEntry.domainName" \
--output text)
# Access service
curl -v http://$SERVICE_DNS/apiUpdating and Deleting Services
Updating Services Using AWS CLI
# Update service
aws vpc-lattice update-service \
--service-identifier $SERVICE_ID \
--auth-type NONE
# Update listener
aws vpc-lattice update-listener \
--service-identifier $SERVICE_ID \
--listener-identifier <LISTENER_ID> \
--default-action '{"forward":{"targetGroups":[{"targetGroupIdentifier":"'$TARGET_GROUP_ID'","weight":100}]}}'Deleting Services Using AWS CLI
# Dissociate from service network
aws vpc-lattice delete-service-network-service-association \
--service-network-service-association-identifier <ASSOCIATION_ID>
# Delete listener
aws vpc-lattice delete-listener \
--service-identifier $SERVICE_ID \
--listener-identifier <LISTENER_ID>
# Delete service
aws vpc-lattice delete-service \
--service-identifier $SERVICE_ID
# Delete target group
aws vpc-lattice delete-target-group \
--target-group-identifier $TARGET_GROUP_IDService Management Using Kubernetes Gateway API
When you update or delete Gateway API resources, the AWS Gateway API Controller automatically updates or deletes VPC Lattice resources.
# Update HTTPRoute
kubectl apply -f updated-http-route.yaml
# Delete HTTPRoute
kubectl delete httproute my-http-route
# Delete Gateway
kubectl delete gateway my-gatewayRouting and Traffic Management
Basic Routing
VPC Lattice provides various routing options including path-based routing, header-based routing, and weighted routing.
Path-based Routing
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: path-based-route
namespace: default
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api/v1
backendRefs:
- name: service-v1
port: 8080
- matches:
- path:
type: PathPrefix
value: /api/v2
backendRefs:
- name: service-v2
port: 8080Header-based Routing
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: header-based-route
namespace: default
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- headers:
- name: "version"
value: "v1"
backendRefs:
- name: service-v1
port: 8080
- matches:
- headers:
- name: "version"
value: "v2"
backendRefs:
- name: service-v2
port: 8080Traffic Splitting and Canary Deployment
VPC Lattice supports traffic splitting and canary deployments through weighted routing.
Weighted Routing Using AWS CLI
# Set up weighted routing
aws vpc-lattice update-listener \
--service-identifier $SERVICE_ID \
--listener-identifier <LISTENER_ID> \
--default-action '{
"forward": {
"targetGroups": [
{
"targetGroupIdentifier": "'$TARGET_GROUP_ID_V1'",
"weight": 80
},
{
"targetGroupIdentifier": "'$TARGET_GROUP_ID_V2'",
"weight": 20
}
]
}
}'Weighted Routing Using Kubernetes Gateway API
Currently, Kubernetes Gateway API does not directly support weighted routing, but the AWS Gateway API Controller supports this feature through annotations.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: weighted-route
namespace: default
annotations:
application-networking.k8s.aws/traffic-weights: |
{
"service-v1": 80,
"service-v2": 20
}
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api
backendRefs:
- name: service-v1
port: 8080
- name: service-v2
port: 8080Health Check Configuration
VPC Lattice supports health checks for target groups.
Health Check Configuration Using AWS CLI
# Update health check configuration
aws vpc-lattice update-target-group \
--target-group-identifier $TARGET_GROUP_ID \
--health-check '{
"enabled": true,
"protocol": "HTTP",
"path": "/health",
"port": 8080,
"healthCheckIntervalSeconds": 30,
"healthCheckTimeoutSeconds": 5,
"healthyThresholdCount": 5,
"unhealthyThresholdCount": 2,
"matcher": {
"httpCode": "200-299"
}
}'Health Check Configuration Using Kubernetes Gateway API
The AWS Gateway API Controller supports health check configuration through annotations.
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: health-check-route
namespace: default
annotations:
application-networking.k8s.aws/health-check: |
{
"enabled": true,
"protocol": "HTTP",
"path": "/health",
"port": 8080,
"intervalSeconds": 30,
"timeoutSeconds": 5,
"healthyThresholdCount": 5,
"unhealthyThresholdCount": 2,
"matcher": {
"httpCode": "200-299"
}
}
spec:
parentRefs:
- name: my-gateway
kind: Gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api
backendRefs:
- name: my-service
port: 8080Security and Authentication
Authentication Methods
VPC Lattice supports the following authentication methods:
- AWS IAM: Authentication using AWS Identity and Access Management
- No Authentication: Allow all requests without authentication
Configuring AWS IAM Authentication
# Create service with IAM authentication
aws vpc-lattice create-service \
--name my-service \
--auth-type AWS_IAMConfiguring IAM Authentication Using Kubernetes Gateway API
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-gateway
namespace: default
annotations:
application-networking.k8s.aws/service-network-id: <SERVICE_NETWORK_ID>
application-networking.k8s.aws/auth-type: "AWS_IAM"
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: http
port: 80
protocol: HTTPResource Policies
VPC Lattice provides fine-grained access control for services and service networks through resource policies.
Setting Service Resource Policy
# Set service resource policy
aws vpc-lattice put-resource-policy \
--resource-arn arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:service/<SERVICE_ID> \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<ACCOUNT_ID>:role/MyRole"
},
"Action": "vpc-lattice:Invoke",
"Resource": "arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:service/<SERVICE_ID>"
}
]
}'Setting Service Network Resource Policy
# Set service network resource policy
aws vpc-lattice put-resource-policy \
--resource-arn arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:servicenetwork/<SERVICE_NETWORK_ID> \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<ACCOUNT_ID>:role/MyRole"
},
"Action": [
"vpc-lattice:CreateServiceNetworkVpcAssociation",
"vpc-lattice:CreateServiceNetworkServiceAssociation"
],
"Resource": "arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:servicenetwork/<SERVICE_NETWORK_ID>"
}
]
}'Cross-Account Access
VPC Lattice supports communication between services across multiple AWS accounts through service networks.
Sharing Service Network Cross-Account
- Share service network using AWS RAM (Resource Access Manager):
# Share service network
aws ram create-resource-share \
--name my-service-network-share \
--resource-arns arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:servicenetwork/<SERVICE_NETWORK_ID> \
--principals arn:aws:organizations::o-<ORGANIZATION_ID>:organization
# Or share with specific account
aws ram create-resource-share \
--name my-service-network-share \
--resource-arns arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:servicenetwork/<SERVICE_NETWORK_ID> \
--principals <TARGET_ACCOUNT_ID>- Accept shared service network in target account:
# Accept share invitation
aws ram accept-resource-share-invitation \
--resource-share-invitation-arn arn:aws:ram:<REGION>:<ACCOUNT_ID>:resource-share-invitation/<INVITATION_ID>- Connect VPC to shared service network in target account:
# VPC association
aws vpc-lattice create-service-network-vpc-association \
--service-network-identifier <SERVICE_NETWORK_ID> \
--vpc-identifier <VPC_ID> \
--security-group-ids <SECURITY_GROUP_ID>TLS Configuration
VPC Lattice supports TLS encryption for services.
TLS Configuration Using AWS CLI
# Create or import ACM certificate
CERTIFICATE_ARN=$(aws acm request-certificate \
--domain-name my-service.example.com \
--validation-method DNS \
--query CertificateArn \
--output text)
# Create TLS listener
aws vpc-lattice create-listener \
--service-identifier $SERVICE_ID \
--name my-tls-listener \
--protocol HTTPS \
--port 443 \
--tls '{
"certificateArn": "'$CERTIFICATE_ARN'",
"mode": "STRICT"
}' \
--default-action '{
"forward": {
"targetGroups": [
{
"targetGroupIdentifier": "'$TARGET_GROUP_ID'"
}
]
}
}'TLS Configuration Using Kubernetes Gateway API
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-tls-gateway
namespace: default
annotations:
application-networking.k8s.aws/service-network-id: <SERVICE_NETWORK_ID>
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: https
port: 443
protocol: HTTPS
tls:
mode: Terminate
certificateRefs:
- kind: Secret
name: my-tls-certMonitoring and Logging
CloudWatch Metrics
VPC Lattice provides various CloudWatch metrics to monitor service performance and status.
Key Metrics
| Metric Name | Description | Dimensions |
|---|---|---|
| RequestCount | Number of processed requests | ServiceId, ServiceName, TargetGroupId |
| HTTP_4XX_Count | Number of 4XX HTTP response codes | ServiceId, ServiceName, TargetGroupId |
| HTTP_5XX_Count | Number of 5XX HTTP response codes | ServiceId, ServiceName, TargetGroupId |
| ProcessedBytes | Number of processed bytes | ServiceId, ServiceName, TargetGroupId |
| TargetProcessingTime | Target processing time (ms) | ServiceId, ServiceName, TargetGroupId |
| HealthyTargetCount | Number of healthy targets | TargetGroupId |
| UnhealthyTargetCount | Number of unhealthy targets | TargetGroupId |
Creating CloudWatch Dashboard
# Create CloudWatch dashboard
aws cloudwatch put-dashboard \
--dashboard-name VPCLatticeMonitoring \
--dashboard-body '{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/VpcLattice", "RequestCount", "ServiceName", "my-service"]
],
"period": 60,
"stat": "Sum",
"region": "<REGION>",
"title": "Request Count"
}
},
{
"type": "metric",
"x": 12,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"metrics": [
["AWS/VpcLattice", "HTTP_4XX_Count", "ServiceName", "my-service"],
["AWS/VpcLattice", "HTTP_5XX_Count", "ServiceName", "my-service"]
],
"period": 60,
"stat": "Sum",
"region": "<REGION>",
"title": "Error Count"
}
}
]
}'CloudWatch Alarms
Set up CloudWatch alarms for VPC Lattice metrics to detect issues early.
# Create 5XX error alarm
aws cloudwatch put-metric-alarm \
--alarm-name VPCLattice-5XX-Errors \
--alarm-description "Alarm when 5XX errors exceed threshold" \
--metric-name HTTP_5XX_Count \
--namespace AWS/VpcLattice \
--dimensions Name=ServiceName,Value=my-service \
--statistic Sum \
--period 60 \
--evaluation-periods 5 \
--threshold 10 \
--comparison-operator GreaterThanThreshold \
--alarm-actions arn:aws:sns:<REGION>:<ACCOUNT_ID>:my-alert-topicAccess Logging
VPC Lattice can send access logs for services to Amazon S3, Amazon CloudWatch Logs, or Amazon Kinesis Data Firehose.
Configuring S3 Access Logging
# Create S3 bucket
aws s3 mb s3://vpc-lattice-access-logs-<ACCOUNT_ID>
# Set bucket policy
aws s3api put-bucket-policy \
--bucket vpc-lattice-access-logs-<ACCOUNT_ID> \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "delivery.logs.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::vpc-lattice-access-logs-<ACCOUNT_ID>/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}'
# Enable access logging
aws vpc-lattice create-access-log-subscription \
--resource-identifier $SERVICE_ID \
--destination-arn arn:aws:s3:::vpc-lattice-access-logs-<ACCOUNT_ID> \
--destination-name my-s3-logsConfiguring CloudWatch Logs Access Logging
# Create log group
aws logs create-log-group \
--log-group-name /aws/vpc-lattice/my-service
# Enable access logging
aws vpc-lattice create-access-log-subscription \
--resource-identifier $SERVICE_ID \
--destination-arn arn:aws:logs:<REGION>:<ACCOUNT_ID>:log-group:/aws/vpc-lattice/my-service \
--destination-name my-cloudwatch-logsAWS X-Ray Integration
VPC Lattice integrates with AWS X-Ray to support distributed tracing.
Enabling X-Ray Tracing
# Enable X-Ray tracing
aws vpc-lattice update-service \
--service-identifier $SERVICE_ID \
--auth-type AWS_IAM \
--tracing-config '{
"enabled": true
}'Enabling X-Ray Tracing Using Kubernetes Gateway API
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-gateway
namespace: default
annotations:
application-networking.k8s.aws/service-network-id: <SERVICE_NETWORK_ID>
application-networking.k8s.aws/xray-tracing: "enabled"
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: http
port: 80
protocol: HTTPBest Practices
Design and Architecture
Service Network Design
- Separate service networks by logical boundaries
- Separate service networks by environment (development, staging, production)
- Separate service networks based on security requirements
Service Naming Conventions
- Use consistent naming conventions
- Include environment, service type, version in names
- Example:
<env>-<service-name>-<version>
Target Group Design
- Place targets with similar characteristics in the same target group
- Optimize health check path and interval
- Set appropriate unhealthy threshold
Performance Optimization
Health Check Optimization
- Set appropriate health check interval (not too short)
- Implement lightweight health check endpoints
- Configure health check path to verify critical dependencies
Connection Reuse
- Implement client-side connection pooling
- Use Keep-Alive headers
- Optimize connection timeout
Caching Strategy
- Implement client-side caching for static content
- Optimize Cache-Control headers
- Integrate CDN if needed
Security Hardening
Principle of Least Privilege
- Grant only minimum required permissions
- Create service-specific IAM policies
- Regular permission review and audit
Network Security
- Restrict traffic using security groups
- Open only required ports
- Consider using VPC endpoints
Encryption
- Use TLS for data encryption in transit
- Use latest TLS versions and cipher suites
- Configure automatic certificate renewal
Monitoring and Observability
Comprehensive Monitoring
- Create CloudWatch dashboards for all services
- Set up alarms for key metrics
- Implement log analysis and anomaly detection
Logging Strategy
- Enable access logging for all services
- Set log retention policies
- Integrate log analysis tools
Distributed Tracing
- Enable X-Ray tracing
- Implement trace correlation between services
- Analyze and visualize trace data
Cost Optimization
Resource Usage Monitoring
- Track service and target group usage
- Identify and remove unused resources
- Use cost allocation tags
Traffic Optimization
- Reduce unnecessary requests
- Optimize response sizes
- Implement batch processing (when possible)
Auto Scaling
- Auto scale targets based on traffic patterns
- Implement scheduled scaling (for predictable traffic patterns)
- Optimize scaling thresholds
Troubleshooting
Common Issues and Solutions
1. Connectivity Issues
Issue: Client cannot connect to VPC Lattice service
Solution:
- Check connectivity between VPC and service network
- Verify security group rules
- Check DNS resolution
- Check target status
# Check VPC association
aws vpc-lattice list-service-network-vpc-associations \
--service-network-identifier $SERVICE_NETWORK_ID
# Check target status
aws vpc-lattice list-targets \
--target-group-identifier $TARGET_GROUP_ID2. Authentication Issues
Issue: Client receives authentication error
Solution:
- Verify IAM policies and permissions
- Check resource policies
- Check signature version and headers
- Check temporary credential expiration
# Check resource policy
aws vpc-lattice get-resource-policy \
--resource-arn arn:aws:vpc-lattice:<REGION>:<ACCOUNT_ID>:service/<SERVICE_ID>3. Routing Issues
Issue: Request is routed to wrong target
Solution:
- Check listener rules and priorities
- Check path patterns and match conditions
- Check target group configuration
- Check weighted routing settings
# Check listener rules
aws vpc-lattice list-listeners \
--service-identifier $SERVICE_ID
# Check target group
aws vpc-lattice get-target-group \
--target-group-identifier $TARGET_GROUP_ID4. Health Check Failures
Issue: Target is failing health checks
Solution:
- Check health check endpoint availability
- Check health check configuration
- Check target application logs
- Check network connectivity
# Check health check configuration
aws vpc-lattice get-target-group \
--target-group-identifier $TARGET_GROUP_ID \
--query "config.healthCheck"
# Check target status
aws vpc-lattice list-targets \
--target-group-identifier $TARGET_GROUP_IDLogging and Debugging
1. Access Log Analysis
You can analyze VPC Lattice access logs to diagnose issues.
# Download access logs from S3
aws s3 cp s3://vpc-lattice-access-logs-<ACCOUNT_ID>/ . --recursive
# Query access logs from CloudWatch Logs
aws logs start-query \
--log-group-name /aws/vpc-lattice/my-service \
--start-time $(date -d '1 hour ago' +%s) \
--end-time $(date +%s) \
--query-string 'fields @timestamp, client_ip, request_path, status_code, request_processing_time | filter status_code >= 400'2. CloudWatch Metrics Analysis
You can analyze CloudWatch metrics to diagnose performance issues.
# Query request count metrics
aws cloudwatch get-metric-statistics \
--namespace AWS/VpcLattice \
--metric-name RequestCount \
--dimensions Name=ServiceName,Value=my-service \
--start-time $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
--period 60 \
--statistics Sum
# Query error metrics
aws cloudwatch get-metric-statistics \
--namespace AWS/VpcLattice \
--metric-name HTTP_5XX_Count \
--dimensions Name=ServiceName,Value=my-service \
--start-time $(date -d '1 hour ago' -u +%Y-%m-%dT%H:%M:%SZ) \
--end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) \
--period 60 \
--statistics Sum3. X-Ray Trace Analysis
You can analyze distributed traces using AWS X-Ray.
# Query X-Ray traces
aws xray get-service-graph \
--start-time $(date -d '1 hour ago' +%s) \
--end-time $(date +%s)
# Query specific trace
aws xray batch-get-traces \
--trace-ids <TRACE_ID>AWS Support and Troubleshooting Tools
1. Creating AWS Support Cases
For severe issues, you can create AWS support cases.
# Create AWS support case
aws support create-case \
--subject "VPC Lattice Connectivity Issue" \
--service-code vpc-lattice \
--category-code connectivity \
--severity-code urgent \
--communication-body "We are experiencing connectivity issues with our VPC Lattice service. Service ID: $SERVICE_ID" \
--language en2. AWS Resource Health Check
You can check AWS service status through the AWS Health Dashboard.
# Check AWS Health events
aws health describe-events \
--filter 'eventTypeCategories=issue,scheduledChange,accountNotification' \
--region <REGION>Conclusion
Amazon VPC Lattice is an AWS application networking service that allows you to securely connect and manage services across different VPCs and accounts. Through integration with EKS, it provides service mesh functionality in Kubernetes environments in a simplified manner.
This document covered the following content:
- Overview: Concepts of VPC Lattice, key use cases, and comparison with other services
- Architecture: VPC Lattice components, service network architecture, and traffic flow
- EKS and VPC Lattice Integration: Integration through AWS Gateway API Controller and its benefits
- Installation and Configuration: AWS Gateway API Controller installation, IAM role setup, and service network creation
- Service Management: VPC Lattice service creation, discovery, access, update, and deletion
- Routing and Traffic Management: Basic routing, traffic splitting, canary deployment, and health checks
- Security and Authentication: Authentication methods, resource policies, cross-account access, and TLS configuration
- Monitoring and Logging: CloudWatch metrics, alarms, access logging, and X-Ray integration
- Best Practices: Design, performance, security, monitoring, and cost optimization
- Troubleshooting: Common issues and solutions, logging and debugging
Effectively implementing and managing VPC Lattice reduces the complexity of microservices architecture, enhances security of service-to-service communication, and improves observability. As an AWS managed service, it provides the benefits of a service mesh while minimizing operational overhead.
References
- Amazon VPC Lattice Official Documentation
- AWS Gateway API Controller Official Documentation
- Kubernetes Gateway API Documentation
- Amazon EKS Workshop - VPC Lattice
- AWS Blog - VPC Lattice Introduction
- AWS Blog - EKS and VPC Lattice Integration
- AWS re:Invent 2022 - VPC Lattice Session
- AWS Samples - VPC Lattice Examples
Quiz
To test what you've learned in this chapter, try the VPC Lattice quiz.