This content originally appeared on DEV Community and was authored by Meidi Airouche
Amazon Bedrock Agents let you build autonomous agents powered by LLMs that can reason, act, and interact with APIs, data sources, and users. Based on the ReAct paradigm, they break down tasks, perform API calls, and integrate with knowledge bases—all without needing to manage underlying infra.
By combining Bedrock Agents with web search APIs, you can extend your chatbot with real-time access to internet content. This unlocks:
- Live web queries in-chat – Keep users in the conversation while retrieving up-to-date info.
- Context-aware actions – Use CoT prompting to decide when to call APIs or search the web.
- Smarter responses – Blend internal knowledge and external data for more relevant replies.
- Fast setup – Add dynamic search with minimal config, and deploy via CloudFormation or CDK.
This integration gives your AI apps richer, more accurate responses while keeping UX simple. Ideal for building more helpful, responsive chatbots—without reinventing the wheel.
Global Solution
An Amazon Bedrock agent acts as the central orchestrator between the user and external web search APIs. It manages the conversation flow, handles optional memory, and the web search.
Search logic is offloaded to an AWS Lambda function, which is responsible for calling a third-party search provider and formatting the results.
We rely on Serper API for the web search. It provides up-to-date, real-time information
API keys for these services are securely stored and accessed via AWS Secrets Manager.
Amazon Bedrock foundation models (Claude 3 Haiku for celerity) handle natural language generation, crafting final answers based on the retrieved content.
Prerequisites
- An AWS account
- AWS CLI configured with your AWS account
Configure the Serper API
Serper API offers a web search service that integrates easily with Amazon Bedrock agents via RESTful calls from a Lambda function. It supports multiple search engines like Google, Bing, and Yahoo, and gives control over query parameters and result types—such as organic results, featured snippets, images, or videos.
This makes Serper a solid choice when you need access to specific search engine features or want results aggregated from multiple sources.
For this example, we’re using Serper API exclusively, with API keys securely stored in AWS Secrets Manager and accessed from the Lambda function during execution. You can use this AWS CLI command to create the secret :
aws secretsmanager create-secret \
--name SERPER_API_KEY \
--description "The API secret key for Serper." \
--secret-string "<SERPER_API_KEY>"
Now that the API is configured, we can start building the web search Amazon Bedrock agent.
Web search AWS Bedrock agent using the console
Create a web search agent
To create a web search agent using the console, complete the following steps:
1) On the Amazon Bedrock console, choose Agents in the navigation pane.
2) Choose Create agent.
3) Enter a name for the agent (such as websearch-agt) and an a description, then choose Create.
We are now in the new agent builder screen, where we can access and edit the configuration of an agent.
4) For Agent resource role, leave the default Create and use a new service role
5) For the model, we choose Anthropic and Claude Haiku 3 (if not available, you can claim access in the model access menu of Bedrock)
6) Here are the instructions for the agent. You can enhance it if you feel comfortable enought to do so :
You are an agent that can help users do research and finding up-to-date information. For up-to-date information always uses web search. Web search uses Google Search - this is great for looking up up-to-date information and current events.
7) Choose Add button in Action groups. Those groups enable us to trigger the lambda function when needed.
8) For Enter action group name, enter action-group-websearch
.
9) For Action group type, select Define with function details so you can specify a function and its parameters as JSON instead of providing an Open API schema.
10) For Action group invocation, set up what the agent does after this action group is identified by the model. Because we want to call the web search APIs, select Quick create a new Lambda function.
With this option, Amazon Bedrock creates a basic Lambda function for your agent that you can later modify on the Lambda console for the use case of calling the web search API. The agent will predict the function and function parameters needed to fulfil its goal and pass the parameters to the Lambda function.
11) Now, configure the Serper API Google search function for the action group with name google-search and the description of your choice.
12) Add a query parameter of type String for the search query.
13) Choose Create to complete the action group creation.
14) Choose Save to save the agent configuration
Lambda function configuration & code
1) On the Lambda console, look for the function with the name action_group_websearch-<code>
.
2) Edit this function and replace the existing code with this one :
import json
import logging
import os
import http.client
import boto3
# Logging setup
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Environment config
AWS_REGION = os.environ.get("AWS_REGION", "us-east-1") # change with your region
ACTION_GROUP_NAME = os.environ.get("ACTION_GROUP", "action-group-websearch")
SERPER_API_KEY = os.environ.get("SERPER_API_KEY")
# Fallback to Secrets Manager if key not in env
if not SERPER_API_KEY:
secrets = boto3.client("secretsmanager", region_name=AWS_REGION)
SERPER_API_KEY = secrets.get_secret_value(SecretId="SERPER_API_KEY")["SecretString"]
# Extracts query parameters
def extract_search_params(event):
if event["actionGroup"] != ACTION_GROUP_NAME:
logger.error("Invalid action group")
return None, None
params = {p["name"]: p["value"] for p in event.get("parameters", [])}
return params.get("search_query"), params.get("target_website", "")
# Calls Serper API
def google_search(query, target_site=""):
if target_site:
query += f" site:{target_site}"
payload = json.dumps({"q": query})
headers = {"X-API-KEY": SERPER_API_KEY, "Content-Type": "application/json"}
conn = http.client.HTTPSConnection("google.serper.dev")
conn.request("POST", "/news", payload, headers)
res = conn.getresponse()
return res.read().decode("utf-8")
# Lambda entry point
def lambda_handler(event, _):
query, site = extract_search_params(event)
if not query:
return {"error": "Missing query"}
results = google_search(query, site)
return {
"response": {
"actionGroup": event["actionGroup"],
"function": event["function"],
"functionResponse": {
"responseBody": {
"TEXT": {
"body": f"Here are the top search results for '{query}': {results}"
}
}
},
},
"messageVersion": event["messageVersion"],
}
3) Click on Deploy to deploy the code.
By default, the Lambda’s default resource policy already has the right premissions to be called from the agent since we created it from the agent action group.
But since we use Secret Manager in the lambda, we need to add this permission to the lambda’s role :
{
"Action": "secretsmanager:GetSecretValue",
"Resource": [
"arn:aws:secretsmanager:<REGION>:<ACCOUNT_ID>:secret:SERPER_API_KEY*"
],
"Effect": "Allow",
"Sid": "GetSecretsManagerSecret"
}
Don’t forget to replace REGION and ACCOUNT_ID with yours.
Test the agent
You’re now ready to test the agent.
1) On the Amazon Bedrock console, on the websearch-agt details page, choose Test.
2) Choose Prepare to load the agent.
3) Ask a question to your agent. Example : “Who won the latest Champions League ?” (yes, I’m french ;D)
4) You should now be able to recieve the answer from your agent. You can now click on Show trace to understand the decision and sources of the agent.
Final thougts
Here we are : we are now able to do a web search in our agentic architectures. This is a powerful and an anovoidable feature that you will obviously need to have.
This content originally appeared on DEV Community and was authored by Meidi Airouche