Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Created April 21, 2026 13:59
Show Gist options
  • Select an option

  • Save koorukuroo/3e2e111c0dc056bd3f06bb1119f03e3f to your computer and use it in GitHub Desktop.

Select an option

Save koorukuroo/3e2e111c0dc056bd3f06bb1119f03e3f to your computer and use it in GitHub Desktop.
import json, boto3
bedrock_agent = boto3.client(
'bedrock-agent-runtime',
region_name='us-east-1'
)
def lambda_handler(event, context):
question = json.loads(event['body'])['question']
response = bedrock_agent.retrieve_and_generate(
input={'text': question},
retrieveAndGenerateConfiguration={
'type': 'KNOWLEDGE_BASE',
'knowledgeBaseConfiguration': {
'knowledgeBaseId': 'YOUR_KB_ID',
'modelArn': 'arn:aws:bedrock:...:anthropic.claude-3-5-sonnet...'
}})
return {'statusCode': 200,
'body': json.dumps({'answer': response['output']['text']})}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment