By using AWS re:Post, you agree to the AWS re:Post Terms of Use

I'm trying to write a lambda functio0n to sync S3 bucket with a knowledgebase and getting an error "Error: 'AgentsforBedrockRuntime' object has no attribute 'start_ingestion_job'"

0

Here is the code used for lambda function. S3 bucket has an event to trigger the following lambda function when a file is added. I want to sync the Knowledgebase with s3 bucket when a new file is added to S3 bucket. Python 3.12 is being used for this lambda function. The IAM policy has full access to S3 bucket and Knowledgebase as well.

import boto3 import json

def lambda_handler(event, context): # Initialize the Bedrock client bedrock = boto3.client('bedrock-agent-runtime')

try:
    # Trigger the sync process for your knowledge base
    response = bedrock.start_ingestion_job(
        knowledgeBaseId='your-knowledgebase-id',
        dataSourceId='your-datasource-id'
    )
    
    print(f"Sync process started. Job ID: {response['jobId']}")
    return {
        'statusCode': 200,
        'body': json.dumps('Sync process initiated successfully')
    }
except Exception as e:
    print(f"Error: {str(e)}")
    return {
        'statusCode': 500,
        'body': json.dumps('Error initiating sync process')
    }

Error observed in CloudWatch Log stream: Error: 'AgentsforBedrockRuntime' object has no attribute 'start_ingestion_job'

1 Answer
1

start_ingestion_job is part of bedrock-agent not bedrock-agent-runtime

Use the correct client as below

import boto3

client = boto3.client('bedrock-agent')

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent.html

If it’s not available in the boto3 version your running you can package the latest and add it as layer to your lambda functions.

profile picture
EXPERT
answered a month ago
AWS
EXPERT
reviewed a month ago
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions