Eashan Kaushik d9f9dffdf8
fix(agentcore-samples): fix for code scanning: Clear-text logging of sensitive information (#286)
* Potential fix for code scanning

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 65: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update setup_database_access.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 41: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 40: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update setup_cognito.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 39: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update retrieve_api_key.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 34: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 33: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 32: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update oauth_test.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 29: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update get_customer_profile.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 28: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update deploy_agent_runtime.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 25: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update credentials_manager.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 18: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update create-gateway.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 15: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update config.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 14: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update cognito_oauth_setup.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 13: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update auth.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Potential fix for code scanning alert no. 9: Clear-text logging of sensitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update deploy_agent_runtime.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update retrieve_api_key.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update retrieve_api_key.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

* Update deploy_agent_runtime.py

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>

---------

Signed-off-by: Eashan Kaushik <50113394+EashanKaushik@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-08-25 16:09:11 -04:00
..
2025-07-21 10:45:13 -04:00
2025-07-23 14:12:58 -04:00

Strands Agent with Bedrock AgentCore Integration

Information Details
Agent type Synchronous
Agentic Framework Strands
LLM model Anthropic Claude 3 Haiku
Components AgentCore Runtime
Example complexity Easy
SDK used Amazon BedrockAgentCore Python SDK

These example demonstrate how to integrate a Strands agents with AWS Bedrock AgentCore, enabling you to deploy your agent as a managed service. You can use the agentcore CLI to configure and launch these agents.

Prerequisites

  • Python 3.10+
  • uv - Fast Python package installer and resolver
  • AWS account with Bedrock Agentcore access

Setup Instructions

1. Create a Python Environment with uv

# Install uv if you don't have it already

# Create and activate a virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

2. Install Requirements

uv pip install -r requirements.txt

3. Configure API Key Provider (for OpenAI + strands example)

If you're using OpenAI models with your Strands agent, you'll need to set up an API key provider:

from bedrock_agentcore.services.identity import IdentityClient
from boto3.session import Session
import boto3

boto_session = Session()
region = boto_session.region_name

# Configure API Key Provider
identity_client = IdentityClient(region=region)
api_key_provider = identity_client.create_api_key_credential_provider({
    "name": "openai-apikey-provider",
    "apiKey": "sk-..." # Replace it with the API key you obtain from OpenAI
})
print(api_key_provider)

4. Understanding the Agent Code

The strands_agent_file_system.py file contains a simple Strands agent with file system capabilities, integrated with Bedrock AgentCore:

import os
os.environ["BYPASS_TOOL_CONSENT"]="true"

from strands import Agent
from strands_tools import file_read, file_write, editor

# Initialize Strands agent with file system tools
agent = Agent(tools=[file_read, file_write, editor])

# Integrate with Bedrock AgentCore
from bedrock_agentcore.runtime import BedrockAgentCoreApp
app = BedrockAgentCoreApp()

@app.entrypoint
def agent_invocation(payload, context):
    """Handler for agent invocation"""
    user_message = payload.get("prompt", "No prompt found in input, please guide customer to create a json payload with prompt key")
    result = agent(user_message)
    return {"result": result.message}

app.run()

5. Configure and Launch with Bedrock AgentCore Toolkit

# Configure your agent for deployment
agentcore configure -e strands_agent_file_system.py

# Deploy your agent
agentcore launch

6. Testing Your Agent

Once deployed, you can test your agent using:

agentcore invoke '{"prompt":"hello"}'