AWS Builder Center

OpenAI Agents on Amazon Bedrock: Private EKS Deployment with Pod Identity

A step-by-step guide to running OpenAI Agents SDK on Amazon Bedrock inside a private EKS cluster. Pod Identity handles credentials, VPC endpoints keep traffic off the internet, and IAM policies lock access to a single model.

What we're building

An AI agent that uses OpenAI's Agents SDK to look up customers and orders — powered by GPT-5.4 running on  Amazon Bedrock . The agent runs on  Amazon EKS  in a fully private VPC with no internet gateway. All AWS service access happens via  VPC endpoints , and authentication is handled by  EKS Pod Identity .

Architecture

Security: Model access restricted at two layers. IAM policy on the pod role (scoped to project/default + openai.gpt-5.4) and a VPCE policy on the endpoint (only allows openai.gpt-5.4 through the network).


Prerequisites

  • AWS account with OpenAI GPT-5.4 enabled in Bedrock (Model Access page)
  • AWS CLI v2 configured with valid credentials
  • Docker or Finch (VM running)
  •  kubectl 
  • Node.js 22+ (for local development)



Step 1: Project structure

Create the following directory structure:
bedrock-agent-eks/
├── src/
│ ├── agent.js
│ ├── server.js
│ ├── package.json
│ ├── .env.example
│ └── public/
│ └── index.html
├── infra/
│ ├── cloudformation.yaml
│ └── k8s/
│ ├── namespace.yaml
│ ├── configmap.yaml
│ ├── serviceaccount.yaml
│ ├── deployment.yaml
│ └── service.yaml
├── Dockerfile
└── deploy.sh



Step 2: The Agent

 src/package.json 

{
"name": "bedrock-agent-eks",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node --no-deprecation server.js"
},
"dependencies": {
"@aws/bedrock-token-generator": "^1.0.0",
"@openai/agents": "^0.1.0",
"dotenv": "^16.4.0",
"express": "^4.21.0",
"openai": "^4.96.0",
"zod": "^3.24.0"
}
}

 src/agent.js 

import "dotenv/config";
import { Agent, run, tool, setTracingDisabled, setDefaultOpenAIClient } from "@openai/agents";
import { getTokenProvider } from "@aws/bedrock-token-generator";
import { z } from "zod";
import OpenAI from "openai";

const region = process.env.AWS_REGION || "us-west-2";
const modelId = process.env.MODEL_ID || "openai.gpt-5.4";

// Generate Bedrock bearer token — works with EKS Pod Identity and local dev
const provideToken = getTokenProvider();

// Disable tracing — it would try to upload to OpenAI's platform
setTracingDisabled(true);

// Configure the Agents SDK to use Bedrock
const client = new OpenAI({
baseURL: `https://bedrock-mantle.${region}.api.aws/openai/v1`,
apiKey: await provideToken(),
project: "default",
});
setDefaultOpenAIClient(client);

// Simulated data
const customers = {
"CUST-100": { name: "Alice Johnson", plan: "enterprise", orders: ["ORD-001", "ORD-002"] },
"CUST-200": { name: "Bob Smith", plan: "starter", orders: ["ORD-003"] },
};

const orders = {
"ORD-001": { status: "shipped", eta: "2025-03-15", carrier: "UPS", items: ["Wireless Keyboard"] },
"ORD-002": { status: "processing", eta: "2025-03-18", carrier: "pending", items: ["Standing Desk"] },
"ORD-003": { status: "delivered", eta: "2025-03-10", carrier: "FedEx", items: ["Monitor Arm"] },
};

// Define tools
const getCustomerInfo = tool({
name: "get_customer_info",
description: "Get customer details including name, plan, and order history.",
parameters: z.object({
customer_id: z.string().describe("Customer ID, e.g. CUST-100"),
}),
execute: async ({ customer_id }) => {
return JSON.stringify(customers[customer_id] || { error: "Customer not found" });
},
});

const getOrderStatus = tool({
name: "get_order_status",
description: "Get the shipping status of an order by order ID.",
parameters: z.object({
order_id: z.string().describe("Order ID, e.g. ORD-001"),
}),
execute: async ({ order_id }) => {
return JSON.stringify(orders[order_id] || { error: "Order not found" });
},
});

// Create the agent
const agent = new Agent({
name: "Customer Support",
instructions: "You help look up customer information and order statuses. When listing orders, always include the status, ETA, carrier, and items for each order.",
model: modelId,
tools: [getCustomerInfo, getOrderStatus],
});

export { agent, run };

 src/server.js 

import express from "express";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { agent, run } from "./agent.js";

const __dirname = dirname(fileURLToPath(import.meta.url));

const app = express();
app.use(express.json());
app.use(express.static(join(__dirname, "public")));

const PORT = process.env.PORT || 3000;

app.get("/health", (_req, res) => {
res.json({ status: "healthy" });
});

// Agent invocation — runs the multi-turn tool loop and returns the final response
app.post("/ask", async (_req, res) => {
const { message } = _req.body;

if (!message) {
return res.status(400).json({ error: "message is required" });
}

try {
const result = await run(agent, message);
res.json({ response: result.finalOutput });
} catch (err) {
console.error("Agent error:", err.message);
res.status(500).json({ error: "Agent invocation failed", details: err.message });
}
});

app.listen(PORT, () => {
console.log(`Agent server running on port ${PORT}`);
});

 src/.env.example 

AWS_REGION=us-west-2
PORT=3000
MODEL_ID=openai.gpt-5.4



Step 3: Dockerfile

FROM node:22-slim

WORKDIR /app

COPY src/package.json src/package-lock.json* ./
RUN npm install --omit=dev

COPY src/ .

EXPOSE 3000

USER node

CMD ["node", "server.js"]



Step 4: Infrastructure (CloudFormation)

A single template creates a fully private VPC, VPC endpoints, EKS cluster, node group, ECR repo, IAM roles, Pod Identity addon, and the Pod Identity association.

 infra/cloudformation.yaml 

AWSTemplateFormatVersion: "2010-09-09"
Description: Infrastructure for Bedrock OpenAI Agent on EKS — fully private

Parameters:
ClusterName:
Type: String
Default: bedrock-openai-agent-cluster
Namespace:
Type: String
Default: bedrock-openai-agent
ServiceAccountName:
Type: String
Default: bedrock-openai-agent-sa
RoleName:
Type: String
Default: bedrock-openai-agent-role
EcrRepoName:
Type: String
Default: bedrock-agent-eks
NodeInstanceType:
Type: String
Default: t3.medium
NodeCount:
Type: Number
Default: 2

Resources:
# VPC — Private Only (no Internet Gateway)
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub "${ClusterName}-vpc"

PrivateSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [0, !GetAZs ""]
MapPublicIpOnLaunch: false

PrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select [1, !GetAZs ""]
MapPublicIpOnLaunch: false

PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC

PrivateSubnet1RTAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet1
RouteTableId: !Ref PrivateRouteTable

PrivateSubnet2RTAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet2
RouteTableId: !Ref PrivateRouteTable

# Security Group for VPC Endpoints
VpcEndpointSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow HTTPS from VPC
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 10.0.0.0/16

# VPC Endpoints
BedrockMantleEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.bedrock-mantle"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
SecurityGroupIds:
- !Ref VpcEndpointSecurityGroup
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowTokenExchange
Effect: Allow
Principal: "*"
Action:
- bedrock-mantle:CallWithBearerToken
Resource: "*"
- Sid: AllowInference
Effect: Allow
Principal: "*"
Action:
- bedrock-mantle:CreateInference
Resource: !Sub "arn:aws:bedrock-mantle:${AWS::Region}:${AWS::AccountId}:project/*"
Condition:
StringEquals:
bedrock-mantle:Model: "openai.gpt-5.4"

ECRApiEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ecr.api"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref VpcEndpointSecurityGroup]

ECRDockerEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ecr.dkr"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref VpcEndpointSecurityGroup]

S3Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.s3"
VpcEndpointType: Gateway
RouteTableIds: [!Ref PrivateRouteTable]

STSEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.sts"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref VpcEndpointSecurityGroup]

EC2Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ec2"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref VpcEndpointSecurityGroup]

EKSAuthEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcId: !Ref VPC
ServiceName: !Sub "com.amazonaws.${AWS::Region}.eks-auth"
VpcEndpointType: Interface
PrivateDnsEnabled: true
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref VpcEndpointSecurityGroup]

# ECR Repository
EcrRepository:
Type: AWS::ECR::Repository
Properties:
RepositoryName: !Ref EcrRepoName
ImageScanningConfiguration:
ScanOnPush: true

# IAM Policy for Bedrock Access
BedrockAccessPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Allows Bedrock Mantle access for OpenAI GPT 5.4
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowTokenExchange
Effect: Allow
Action:
- bedrock-mantle:CallWithBearerToken
Resource: "*"
- Sid: AllowInference
Effect: Allow
Action:
- bedrock-mantle:CreateInference
Resource: !Sub "arn:aws:bedrock-mantle:${AWS::Region}:${AWS::AccountId}:project/default"
Condition:
StringEquals:
bedrock-mantle:Model: "openai.gpt-5.4"

# IAM Role for Pod Identity
BedrockAgentRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref RoleName
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: pods.eks.amazonaws.com
Action: ["sts:AssumeRole", "sts:TagSession"]
ManagedPolicyArns:
- !Ref BedrockAccessPolicy

# EKS Cluster
EksClusterRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${ClusterName}-cluster-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: eks.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonEKSClusterPolicy

EksCluster:
Type: AWS::EKS::Cluster
Properties:
Name: !Ref ClusterName
Version: "1.31"
RoleArn: !GetAtt EksClusterRole.Arn
ResourcesVpcConfig:
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
EndpointPublicAccess: true
EndpointPrivateAccess: true

# Pod Identity
PodIdentityAddon:
Type: AWS::EKS::Addon
DependsOn: EksCluster
Properties:
ClusterName: !Ref ClusterName
AddonName: eks-pod-identity-agent

PodIdentityAssociation:
Type: AWS::EKS::PodIdentityAssociation
DependsOn: PodIdentityAddon
Properties:
ClusterName: !Ref ClusterName
Namespace: !Ref Namespace
ServiceAccount: !Ref ServiceAccountName
RoleArn: !GetAtt BedrockAgentRole.Arn

# Node Group
NodeGroupRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${ClusterName}-node-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: ec2.amazonaws.com
Action: "sts:AssumeRole"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly

NodeGroup:
Type: AWS::EKS::Nodegroup
DependsOn: EksCluster
Properties:
ClusterName: !Ref ClusterName
NodegroupName: !Sub "${ClusterName}-nodes"
NodeRole: !GetAtt NodeGroupRole.Arn
Subnets: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
InstanceTypes: [!Ref NodeInstanceType]
ScalingConfig:
DesiredSize: !Ref NodeCount
MinSize: 1
MaxSize: !Ref NodeCount



Step 5: Kubernetes Manifests

 infra/k8s/namespace.yaml 

apiVersion: v1
kind: Namespace
metadata:
name: bedrock-openai-agent

 infra/k8s/configmap.yaml 

apiVersion: v1
kind: ConfigMap
metadata:
name: bedrock-openai-agent-config
namespace: bedrock-openai-agent
data:
AWS_REGION: "us-west-2"
PORT: "3000"
MODEL_ID: "openai.gpt-5.4"

 infra/k8s/serviceaccount.yaml 

apiVersion: v1
kind: ServiceAccount
metadata:
name: bedrock-openai-agent-sa
namespace: bedrock-openai-agent

 infra/k8s/deployment.yaml 

apiVersion: apps/v1
kind: Deployment
metadata:
name: bedrock-openai-agent
namespace: bedrock-openai-agent
spec:
replicas: 2
selector:
matchLabels:
app: bedrock-openai-agent
template:
metadata:
labels:
app: bedrock-openai-agent
spec:
serviceAccountName: bedrock-openai-agent-sa
containers:
- name: agent
image: ${ECR_URI}:${IMAGE_TAG}
imagePullPolicy: Always
ports:
- containerPort: 3000
env:
- name: AWS_REGION
valueFrom:
configMapKeyRef:
name: bedrock-openai-agent-config
key: AWS_REGION
- name: PORT
valueFrom:
configMapKeyRef:
name: bedrock-openai-agent-config
key: PORT
- name: MODEL_ID
valueFrom:
configMapKeyRef:
name: bedrock-openai-agent-config
key: MODEL_ID
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 10
periodSeconds: 30
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"

 infra/k8s/service.yaml 

apiVersion: v1
kind: Service
metadata:
name: bedrock-openai-agent
namespace: bedrock-openai-agent
spec:
selector:
app: bedrock-openai-agent
ports:
- port: 80
targetPort: 3000
type: ClusterIP



Step 6: Deploy Script

A single script handles everything: CloudFormation stack, Docker build/push to ECR, and K8s deployment. Safe to run multiple times as it only updates what changed.

 deploy.sh 

#!/bin/bash
set -euo pipefail

STACK_NAME="bedrock-openai-agent-stack"
CLUSTER_NAME="bedrock-openai-agent-cluster"
REGION="us-west-2"
ECR_REPO="bedrock-agent-eks"
IMAGE_TAG="latest"

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
ECR_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${ECR_REPO}"

echo "==> Deploying infrastructure (CloudFormation)..."
aws cloudformation deploy \
--template-file infra/cloudformation.yaml \
--stack-name "$STACK_NAME" \
--region "$REGION" \
--capabilities CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset

echo "==> Updating kubeconfig..."
aws eks update-kubeconfig --name "$CLUSTER_NAME" --region "$REGION"

echo "==> Building Docker image..."
docker build --platform linux/amd64 -t "$ECR_REPO" .

echo "==> Logging into ECR..."
aws ecr get-login-password --region "$REGION" | \
docker login --username AWS --password-stdin "${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com"

echo "==> Pushing image to ECR..."
docker tag "${ECR_REPO}:${IMAGE_TAG}" "${ECR_URI}:${IMAGE_TAG}"
docker push "${ECR_URI}:${IMAGE_TAG}"

echo "==> Deploying to EKS..."
kubectl apply -f infra/k8s/namespace.yaml
kubectl apply -f infra/k8s/configmap.yaml
kubectl apply -f infra/k8s/serviceaccount.yaml
export ECR_URI IMAGE_TAG
envsubst < infra/k8s/deployment.yaml | kubectl apply -f -
kubectl apply -f infra/k8s/service.yaml

echo "==> Waiting for pods to be ready..."
kubectl rollout status deployment/bedrock-openai-agent -n bedrock-openai-agent --timeout=120s

echo ""
echo "Done! Access the app:"
echo " kubectl port-forward svc/bedrock-openai-agent 8080:80 -n bedrock-openai-agent"
echo " Open http://localhost:8080"
Make it executable:
chmod +x deploy.sh



Step 7: Deploy

./deploy.sh
First run takes ~15-20 minutes (mostly CloudFormation creating the EKS cluster). Subsequent runs are fast.



Step 8: Access the app

Since the VPC is fully private, use port-forward:
kubectl port-forward svc/bedrock-openai-agent 8080:80 -n bedrock-openai-agent

Test it:

curl -X POST http://localhost:8080/ask \
-H "Content-Type: application/json" \
-d '{"message": "Look up customer CUST-100 and tell me the status of all their orders."}'
In production, you'd replace port-forward with an internal ALB accessible via VPN or Direct Connect.
Want a chat UI ? Build your own frontend that calls  POST /ask  — here's a sample index.html:
index.html




Local Development

For local testing without deploying to EKS (requires valid AWS credentials):
cd src
npm install
cp .env.example .env
npm start



Cleanup

kubectl delete namespace bedrock-openai-agent
aws cloudformation delete-stack --stack-name bedrock-openai-agent-stack --region us-west-2


Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article