8000 GitHub - aws-samples/sample-bedrock-agent-powertools-for-aws: Learn how to create an Amazon Bedrock Agent using Powertools for AWS (TypeScript) Event Handler for Bedrock Agent Functions.
[go: up one dir, main page]

Skip to content

aws-samples/sample-bedrock-agent-powertools-for-aws

Bedrock Agent with Powertools for AWS

This sample demonstrates how to create an Amazon Bedrock Agent using Powertools for AWS (TypeScript) Event Handler for Bedrock Agent Functions.

Prerequisites

Before you can deploy this sample, you must request access to a foundation model in Amazon Bedrock. Please refer to this page for more information.

Once you have access, take a note of the model ID (i.e. amazon.nova-pro-v1:0) and AWS Region (i.e. us-west-2) as you will need them to deploy the sample.

Finally, please make sure to review the IAM role and permissions defined in lib/bedrockagents-stack.ts, especially the one for the Bedrock Agent (search for agentRole in the file). Currently, the sample uses a bedrock:* permission to allow you to test the agent and experiment with it.

Before deploying an agent in production, review the Bedrock Agent documentation to ensure you have the right permissions in place.

Deploy

After cloning this repository, you can deploy the sample using the AWS CDK.

npm ci
npm run cdk deploy -- --context modelId=amazon.nova-pro-v1:0 --region us-west-2

The sample will create a Bedrock Agent with a single AWS Lambda function that uses the Powertools for AWS Lambda Event Handler for Bedrock Agent Functions. The function is written in TypeScript, but you can adapt it to your preferred language using the same Powertools for AWS feature available in Python and .NET.

Test

Use the Bedrock Console to test the agent, try asking it questions like:

  • What's the weather in Seattle?
  • What's the weather like in Madrid and in Rome?

You can then go in CloudWatch Log Insights and run the following query to see the logs:

fields message, level, timestamp, requestId, correlation_id as sessionId, tool
| filter sessionId = "536254204126922" # Replace with your session ID
# | filter city = "city_name" # Uncomment to filter by city
| sort timestamp asc
| limit 10000

Cleanup

npm run cdk destroy

License

MIT-0

About

Learn how to create an Amazon Bedrock Agent using Powertools for AWS (TypeScript) Event Handler for Bedrock Agent Functions.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  
0