mirror of
https://github.com/awslabs/amazon-bedrock-agentcore-samples.git
synced 2025-09-08 20:50:46 +00:00
* updated README.md file with bearer token generation * updated README.md file with bearer token generation-removed client id and secret credentials * removed hardcoded domain * added agent runtime, frontend, observability and agentcore identity * update README.md file to reflect frontend testing
Device Management Module
This module implements the core functionality of the Device Management system, including the Lambda function that handles all MCP server tools, DynamoDB models, and testing utilities.
Components
lambda_function.py
: Main Lambda handler that implements all MCP toolsdynamodb_models.py
: DynamoDB table definitions and initializationsynthetic_data.py
: Script to generate synthetic test datatest_lambda.py
: Script to test the Lambda function locallydeploy.sh
: Deployment script for the Lambda functionrequirements.txt
: Python dependencies
Setup
- Create a
.env
file in this directory with the following variables:
# AWS configuration
AWS_REGION=us-west-2
# Lambda configuration
LAMBDA_FUNCTION_NAME=DeviceManagementLambda
LAMBDA_ROLE_NAME=DeviceManagementLambdaRole
# Agent Gateway IAM configuration
AGENT_GATEWAY_POLICY_NAME=AgentGatewayAccess
AGENT_GATEWAY_ROLE_NAME=AgentGatewayAccessRole
- Install the required Python packages:
pip install -r requirements.txt
Deployment
You can deploy the Lambda function using the provided deployment script:
chmod +x deploy.sh
./deploy.sh
The deployment script performs the following actions:
- Packages the Lambda function code with dependencies
- Creates an IAM role with necessary permissions (if it doesn't exist)
- Creates or updates the Lambda function
- Configures the function with appropriate memory and timeout settings
DynamoDB Tables
The function uses the following DynamoDB tables in the configured AWS region:
Devices
: Device inventory and statusDeviceSettings
: Device configuration settingsWifiNetworks
: WiFi network configurationsUsers
: User accounts and profilesUserActivities
: User activity logs
Generate Test Data
To populate the tables with synthetic test data:
python synthetic_data.py
Test the Lambda Function
You can test the Lambda function locally using the provided test script:
python test_lambda.py
This script tests all available tools and verifies that they work correctly.
IAM Permissions
The Lambda function requires the following IAM permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:UpdateItem"
],
"Resource": [
"arn:aws:dynamodb:us-west-2:*:table/Devices",
"arn:aws:dynamodb:us-west-2:*:table/DeviceSettings",
"arn:aws:dynamodb:us-west-2:*:table/WifiNetworks",
"arn:aws:dynamodb:us-west-2:*:table/Users",
"arn:aws:dynamodb:us-west-2:*:table/UserActivities",
"arn:aws:dynamodb:us-west-2:*:table/UserActivities/index/ActivityTypeIndex"
]
}
]
}
Available MCP Tools
The Lambda function exposes the following MCP tools:
list_devices
: Lists all devices in the systemget_device_settings
: Retrieves settings for a specific devicelist_wifi_networks
: Lists WiFi networks for a specific devicelist_users
: Lists all users in the systemquery_user_activity
: Queries user activity within a time periodupdate_wifi_ssid
: Updates the SSID for a WiFi networkupdate_wifi_security
: Updates the security type for a WiFi network
Integration with Other Modules
- Gateway Module: The Lambda function is the target for the gateway created in the gateway module.
- Frontend Module: The frontend communicates with this Lambda function through the gateway.