AWS Builder Center

Build an Amazon Bedrock AgentCore Real-Time Voice and Video Streaming Architecture Using the AWS Management Console

Build an Amazon Bedrock AgentCore Real-Time Voice and Video Streaming Architecture Using the AWS Management Console

Series: Financial Service (19 articles)

  1. …
  2. 15
    Build an Amazon Bedrock AgentCore Real-Time Voice and Video Streaming Architecture Using the AWS Management Console This article
Dev @ Vertex Macro

Build an Amazon Bedrock AgentCore Real-Time Voice and Video Streaming Architecture Using the AWS Management Console

This guide provides a complete implementation procedure that primarily uses the AWS Management Console, supported by AWS CloudShell and the AgentCore CLI. The objective is to establish a real-time WebRTC voice and video streaming architecture between a browser and Amazon Bedrock AgentCore Runtime, using the managed TURN service from Amazon Kinesis Video Streams for media relay.
Important note: The current AWS official example primarily demonstrates bidirectional voice streaming in a browser and uses a speech-to-speech model such as Amazon Nova Sonic to process audio. Video can use the same WebRTC connection, but the application must sample video frames and send them to a model that supports image input or to a video-processing pipeline. Do not assume that a speech model can process video directly.

1. Target Technical Architecture

A user signs in to a web application through a browser and obtains short-lived authorization. The browser then creates a WebRTC connection and generates an SDP offer. The Web Application/API Layer validates the user's identity, processes SigV4 or OAuth 2.0 authorization, and sends the SDP offer to the /invocations endpoint of Amazon Bedrock AgentCore Runtime.
Amazon Bedrock AgentCore Runtime handles WebRTC signaling, SDP offer and answer exchange, ICE candidate exchange, session management, and agent execution. Runtime is deployed in VPC network mode and connects to the enterprise VPC through an elastic network interface in a private subnet.
Real-time audio and video media is transported through WebRTC. Media packets are protected by ICE, DTLS, and SRTP, and are relayed between the user's browser and AgentCore Runtime through Amazon Kinesis Video Streams Managed TURN Relay. The VPC that hosts Runtime must have outbound connectivity through a NAT Gateway and must permit outbound UDP traffic to the TURN endpoints.
AgentCore Runtime invokes an Amazon Bedrock foundation model through the AWS SDK. Audio can be sent to a speech-to-speech model for real-time speech understanding and spoken responses. The Runtime application samples video frames according to policy and sends them to a multimodal model that supports image input or to a video-processing pipeline. The agent can also perform approved tool calls.
The enterprise architecture can additionally integrate Amazon Cognito or an enterprise identity provider, AgentCore Identity, AgentCore Gateway, AgentCore Memory, Amazon CloudWatch, AWS CloudTrail, Amazon S3, and AWS KMS. These components provide user authentication, downstream service authorization, tool integration, controlled memory, technical monitoring, auditing, data storage, and encryption.
WebRTC on Amazon Bedrock AgentCore Runtime must use VPC network mode. Media traffic must pass through a TURN relay, and the Runtime VPC must allow outbound UDP traffic to the TURN endpoints. WebRTC signaling can use either the AgentCore Runtime invoke API or a Kinesis Video Streams signaling channel.

2. Select an AWS Region

First, select an AWS Region that supports all of the following services and models:
  • Amazon Bedrock AgentCore Runtime
  • Amazon Kinesis Video Streams
  • The intended Amazon Bedrock model
  • Availability Zones supported for VPC mode
  • Supporting services such as Amazon Cognito, CloudWatch, and CloudTrail
The official AWS voice example uses us-west-2. AgentCore VPC connectivity supports only specific Availability Zone IDs in each Region. Runtime creation will fail if the selected subnet is in an unsupported Availability Zone.
Recommended starting Region:
1
2
Region: US West (Oregon)
Region code: us-west-2
If the data must remain in Asia, evaluate ap-southeast-1, ap-northeast-1, or another Region allowed by the organization's data policy, and verify that the selected model is available there.

3. Enable Bedrock Model Access

  • Sign in to the AWS Management Console.
  • Switch to the Region selected for deployment.
  • Search for and open Amazon Bedrock.
  • Go to Bedrock configurations -> Model access.
  • Locate the intended speech or multimodal model.
  • Choose Request model access, or enable the model through the current console interface.
  • Wait until the model becomes available for use.
The official WebRTC example uses Amazon Nova Sonic for real-time speech-to-speech processing. Before production adoption, verify the model ID, streaming API, supported languages, Region availability, quotas, and audio format.

4. Create the VPC, Public Subnets, and Private Subnets

4.1 Create the Network in the VPC Console

  • Search for VPC in the AWS Console.
  • Choose Your VPCs.
  • Choose Create VPC.
  • Select VPC and more.
  • Enter the following values:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Name tag:
agentcore-webrtc-vpc

IPv4 CIDR:
10.20.0.0/16

Number of Availability Zones:
2

Number of public subnets:
2

Number of private subnets:
2

NAT gateways:
1 per AZ for production
In 1 AZ for a proof of concept

VPC endpoints:
Do not create yet
  • Enable DNS hostnames and DNS resolution.
  • Choose Create VPC.
Place the AgentCore Runtime elastic network interfaces in private subnets. Placing an ENI in a public subnet does not automatically provide internet connectivity. To access Kinesis Video Streams TURN, the private subnet must reach the internet through a NAT Gateway.

4.2 Verify the Routes

Confirm that the public subnet route table contains:
1
0.0.0.0/0 -> Internet Gateway
Confirm that the private subnet route table contains:
1
0.0.0.0/0 -> NAT Gateway
For production, use at least two private subnets in different Availability Zones to avoid a single-AZ failure. For a proof of concept, you can follow the official example and start with one public subnet, one private subnet, and one NAT Gateway.

5. Create a Security Group

  • Go to VPC -> Security groups.
  • Choose Create security group.
  • Enter the following values:
1
2
3
4
5
6
7
8
Security group name:
agentcore-webrtc-runtime-sg

Description:
Outbound media and AWS service access for AgentCore WebRTC Runtime

VPC:
agentcore-webrtc-vpc

Inbound Rules

If Runtime does not need to accept direct connections from other resources in the VPC, no general inbound rule is required. The AgentCore platform manages its service invocation entry point.
If Runtime must access an internal API, do not add an inbound rule to this Runtime security group. Instead, configure the target API or load balancer to allow traffic from this security group.

Outbound Rules

For a proof of concept, begin with:
1
2
All traffic
Destination: 0.0.0.0/0
After validation, progressively restrict outbound traffic to:
  • HTTPS TCP 443
  • Outbound UDP traffic required by TURN
  • DNS TCP/UDP 53
  • Specific ports used by internal organizational APIs
  • Required AWS VPC endpoints
AgentCore WebRTC explicitly requires the VPC to send UDP traffic to TURN endpoints. If only TCP 443 is permitted, signaling can succeed while the media connection still fails.

6. Create a Kinesis Video Streams Signaling Channel

  • Search for Kinesis Video Streams in the AWS Console.
  • Open Signaling channels.
  • Choose Create signaling channel.
  • Enter the following values:
1
2
3
4
5
Signaling channel name:
agentcore-webrtc-channel

Message time to live:
Use the default or the value required by the organization
  • After it is created, copy the following information:
1
2
3
Channel ARN
Channel name
Region
In this architecture, the Kinesis Video Streams signaling channel is primarily used to obtain temporary TURN credentials. The application first calls GetSignalingChannelEndpoint to obtain the HTTPS endpoint, and then calls GetIceServerConfig against that endpoint to obtain the TURN URI, username, password, and TTL.

7. Create the AgentCore Runtime Execution Role

  • Open the IAM Console.
  • Go to Roles -> Create role.
  • Select the trusted service appropriate for AgentCore Runtime, or allow the AgentCore CLI to create the role first and then add permissions in the IAM Console.
  • Use the following role name:
1
AgentCoreWebRTCRuntimeRole

7.1 Kinesis Video Streams Permissions

Create the following inline policy:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KvsSignalingChannelRead",
"Effect": "Allow",
"Action": [
"kinesisvideo:DescribeSignalingChannel",
"kinesisvideo:GetSignalingChannelEndpoint",
"kinesisvideo:GetIceServerConfig"
],
"Resource": "arn:aws:kinesisvideo:REGION:ACCOUNT_ID:channel/agentcore-webrtc-channel/*"
}
]
}
GetIceServerConfig returns the WebRTC ICE/TURN configuration, including the URI, username, password, and credential lifetime. The application must not write these temporary credentials to persistent logs or embed them in frontend source code.

7.2 Bedrock Model Permissions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InvokeApprovedBedrockModel",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:REGION::foundation-model/APPROVED_MODEL_ID"
]
}
]
}
If the speech model uses a different bidirectional streaming API, add the corresponding actions specified in that model's official documentation. Avoid setting Resource to * in a production environment.

7.3 CloudWatch Logs Permissions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "WriteRuntimeLogs",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:REGION:ACCOUNT_ID:log-group:/aws/bedrock-agentcore/*"
}
]
}

8. Prepare the AgentCore WebRTC Application

AWS provides a minimal WebRTC Voice Agent example with the following structure:
1
2
3
4
5
6
7
8
9
10
11
agent/
bot.py
kvs.py
audio.py
nova_sonic.py
requirements.txt
Dockerfile

server/
index.html
server.py
bot.py provides the FastAPI /invocations entry point and handles WebRTC offer/answer and ICE processing. kvs.py obtains the KVS TURN configuration. audio.py handles audio resampling. nova_sonic.py manages bidirectional streaming with the speech model.
Use AWS CloudShell:
1
2
git clone https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
cd amazon-bedrock-agentcore-samples/01-features/02-host-your-agent/01-runtime/03-advanced/03-bidirectional-streaming/05-bidirectional-streaming-webrtc
Install the AgentCore Starter Toolkit:
1
python3 -m pip install --user bedrock-agentcore-starter-toolkit

9. Configure Runtime Through the AgentCore CLI

Although VPC, IAM, KVS channel, and some Runtime settings can be configured through the AWS Console, the official AWS WebRTC example uses the AgentCore CLI to build the container and deploy Runtime.
Set the environment variables:
1
2
3
export AWS_REGION=us-west-2
export SUBNET_IDS=subnet-private-a,subnet-private-b
export SECURITY_GROUP_ID=sg-agentcore-webrtc
Enter the agent directory:
1
cd agent
Configure Runtime:
1
2
3
4
5
6
7
8
agentcore configure \
-e bot.py \
--deployment-type container \
--disable-memory \
--vpc \
--subnets "$SUBNET_IDS" \
--security-groups "$SECURITY_GROUP_ID" \
--non-interactive
WebRTC must use VPC network mode. The official example specifically notes that public network mode does not support the outbound UDP connectivity required by this architecture.

10. Deploy AgentCore Runtime

Run:
1
2
3
agentcore deploy \
--env KVS_CHANNEL_NAME=agentcore-webrtc-channel \
--env AWS_REGION=us-west-2
The deployment process normally performs the following tasks:
  • Creates or uses an ECR repository.
  • Builds an ARM64 container through CodeBuild.
  • Creates AgentCore Runtime.
  • Connects Runtime to the selected private subnets.
  • Creates an ENI.
  • Returns the Runtime ARN and execution role.
The official example indicates that Docker is not necessarily required locally because the deployment can build the ARM64 container through CodeBuild.
Record the following values after deployment:
1
2
3
4
Runtime ARN
Runtime ID
Execution role name
Region

11. Verify Runtime in the AgentCore Console

  • Open the Amazon Bedrock AgentCore Console.
  • Go to AgentCore Runtime.
  • Select the Runtime that you created.
  • Verify the following values:
1
2
3
4
5
6
7
Status: Ready / Active
Deployment type: Container
Network mode: VPC
VPC: agentcore-webrtc-vpc
Subnets: private subnets
Security groups: agentcore-webrtc-runtime-sg
Execution role: AgentCoreWebRTCRuntimeRole
If you create Runtime manually from the Console, use the following process:
  • Select or create an AgentCore Runtime.
  • Select the ECR image.
  • Under Network configuration, select VPC.
  • Select the VPC.
  • Select the private subnets.
  • Select the security group to apply to the ENIs.
  • Save the configuration.

12. Frontend WebRTC Process

The browser must perform the following sequence:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: true
});

const peerConnection = new RTCPeerConnection({
iceServers: temporaryIceServers
});

for (const track of stream.getTracks()) {
peerConnection.addTrack(track, stream);
}

const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);

// Send the SDP offer to Amazon Bedrock AgentCore Runtime /invocations
// Receive the SDP answer returned by Runtime
await peerConnection.setRemoteDescription(answer);
The complete connection sequence is as follows:
  • The browser calls Runtime to obtain KVS TURN credentials.
  • The browser creates an SDP offer.
  • Runtime creates the corresponding WebRTC peer connection.
  • Runtime returns the SDP answer.
  • Both sides exchange ICE candidates.
  • A media path is established through KVS TURN.
  • The browser streams real-time audio and video.
  • Runtime sends the audio to the speech model.
  • Runtime streams the model's audio response back to the browser.

13. Add Video Processing

The official AWS minimal example primarily processes audio. To add video, do not send every video frame to the model. Instead, use an on-demand frame-sampling approach. After AgentCore Runtime receives the WebRTC video track, a frame sampler in the application captures frames according to business requirements and data policy. For example, it can capture one frame every one to three seconds or capture a frame only when the user explicitly requests screen analysis.
The Runtime application should resize the captured frames and compress them in a format such as JPEG or WebP to control network traffic, model latency, and inference cost. If the image may contain account data, customer information, personal data, credentials, screen notifications, or other sensitive content, mask, crop, or remove that content before sending the image to the model.
After preprocessing, the application sends the selected frames to an approved Amazon Bedrock multimodal model that supports image input or to an approved image-processing pipeline. The returned image description, field extraction result, or other structured observation can be added to the current voice-agent conversation context, allowing the agent to answer questions based on observable content or proceed with an approved workflow. Do not assume that the speech model can process an arbitrary video stream directly. The application must explicitly implement video-frame decoding, sampling, conversion, and model forwarding.
The video pipeline must handle all of the following items:
  • WebRTC video-track decoding
  • Frame sampling
  • Maximum image dimensions
  • Image compression
  • Model-supported formats
  • Model invocation frequency
  • Image-retention policy
  • User consent for camera access
  • Sensitive-information masking
The safest default configuration keeps the camera off by default, disables recording, does not preserve raw video, captures frames only when explicitly requested or required by an approved business workflow, and explicitly prohibits inferring emotion, mental health, or personality from a person's face, voice, gaze, posture, or other behavioral signals.
Recommended defaults:
1
2
3
4
5
Camera: Off by default
Recording: Disabled
Raw video storage: Disabled
Frame sampling: On demand
Facial or emotion inference: Prohibited

14. Test the Connection

Start the example web server:
1
2
3
cd ../server
python3 -m pip install -r requirements.txt
python3 server.py
Open the following address in a browser:
1
http://localhost:7860
Enter the Runtime ARN, choose Connect, allow microphone and camera access, and then perform a speaking test. The official example allows the Runtime ARN to be entered in the browser. After the connection is established, it streams voice in real time and plays the model's spoken response.

Browser States to Verify

1
2
3
4
5
6
7
ICE gathering state: complete
ICE connection state: connected
Peer connection state: connected
Selected candidate type: relay
Audio packets sent: increasing
Audio packets received: increasing
Video packets sent: increasing
Because the AgentCore Runtime WebRTC architecture requires TURN, the selected ICE candidate pair should show relay rather than relying on a direct host or server-reflexive path.

15. CloudWatch Monitoring

In CloudWatch -> Log groups, review the Runtime logs and capture the following data:
  • WebRTC session ID
  • ICE connection state
  • TURN credential request success or failure
  • SDP negotiation latency
  • Packet loss
  • Jitter
  • Round-trip time
  • Audio underrun
  • Model time to first response
  • Model streaming duration
  • Video-frame sampling rate
  • Tool-call latency
  • Session termination reason
Do not log the following data:
1
2
3
4
5
6
7
TURN password
AWS credentials
Access token
Complete raw audio
Complete raw video
Unredacted transcript
Sensitive customer data

16. Troubleshooting

SDP Succeeds, but There Is No Audio

TURN UDP traffic is usually blocked. Verify the following paths and rules:
1
2
3
4
Private subnet -> NAT Gateway
NAT Gateway -> Internet Gateway
Security group outbound UDP
Network ACL outbound and return traffic
Successful signaling does not prove that media packets can pass. The AgentCore WebRTC architecture requires the VPC to send UDP traffic to the TURN endpoint.

GetIceServerConfig Returns AccessDenied

Verify that the Runtime execution role allows:
1
2
3
kinesisvideo:DescribeSignalingChannel
kinesisvideo:GetSignalingChannelEndpoint
kinesisvideo:GetIceServerConfig
Also verify that the channel ARN, Region, and AWS account ID are correct. GetIceServerConfig must be called for the specified signaling channel ARN.

Runtime Fails to Create an ENI

Verify the following items:
  • The subnets are in Availability Zone IDs supported by AgentCore.
  • The deployment identity has permission to create the service-linked role.
  • The VPC has available IP addresses.
  • The security group is in the same VPC.
AgentCore uses AWSServiceRoleForBedrockAgentCoreNetwork to create an ENI in the specified subnet.

Voice Latency Is High

Measure the following components separately and in order:
1
2
3
4
5
6
7
Browser capture latency
TURN relay RTT
Packet loss and jitter
Runtime processing latency
Model time to first response
Audio synthesis latency
Browser playback buffer
Do not measure only model latency. WebRTC can reduce media-transport latency, but it does not guarantee that the complete model interaction will remain within a fixed number of milliseconds.

17. Production Security Checklist

Complete at least the following controls before production deployment:
  • Use Amazon Cognito, an enterprise identity provider, or OAuth 2.0 instead of placing AWS access keys in the browser.
  • Place Runtime in at least two private subnets in different Availability Zones.
  • Use least-privilege IAM policies.
  • Keep TURN credentials short-lived.
  • Enable CloudTrail.
  • Enable VPC Flow Logs.
  • Use AWS KMS to encrypt logs and memory.
  • Keep video disabled by default.
  • Do not preserve raw audio or video by default.
  • Allow users to stop the microphone and camera immediately.
  • Apply deterministic policy checks before executing tools.
  • Require explicit human confirmation for high-risk operations.
  • Do not infer psychological or emotional state from a person's voice, face, gaze, or posture.
  • Configure service quota alarms for AgentCore Runtime, Bedrock models, and KVS TURN.

18. Clean Up the Test Environment

Delete Runtime:
1
agentcore destroy
Then delete the following resources through the AWS Console, in this order:
  • AgentCore Runtime
  • ECR image and repository
  • CodeBuild project
  • Kinesis Video Streams signaling channel
  • CloudWatch log groups
  • Inline IAM policies and test roles
  • NAT Gateway
  • Elastic IP
  • VPC
After AgentCore Runtime is deleted, the related ENIs can take several hours to be removed automatically. If the VPC cannot be deleted immediately, wait for the ENI cleanup to complete.

Final Recommendation

In the first phase, implement the official voice-only WebRTC and KVS TURN path. Verify VPC, UDP, IAM, SDP, ICE, TURN, and model streaming before proceeding. In the second phase, add the video track and low-frequency frame sampling. In the third phase, integrate AgentCore Identity, Memory, Gateway, enterprise authentication, observability, and production governance controls. This phased approach separates network, media, model, and authorization issues and avoids introducing too many variables at once.

References

Series: Financial Service (19 articles)

  1. …
  2. 15
    Build an Amazon Bedrock AgentCore Real-Time Voice and Video Streaming Architecture Using the AWS Management Console This article
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