To test your update, run the following code to invoke Anthropic Claude Opus 4.6:
import boto3
import botocore
import json
def lambda_handler(event, context):
print("Boto3 version:", boto3.__version__)
print("Botocore version:", botocore.__version__)
bedrock_runtime = boto3.client(service_name='bedrock-runtime', region_name='us-east-1', endpoint_url='https://bedrock-runtime.us-east-1.amazonaws.com')
# event = {
# "anthropic_version": "bedrock-2023-05-31",
# "max_tokens": 4000,
# "top_k": 250,
# "top_p": 1,
# "messages": [
# {
# "role": "user",
# "content": "Why is the sky blue?"
# }
# ],
# "stop_sequences": ["Command:"]
# }
print(f"EVENT: {event}")
bedrock_str = json.dumps(event)
print(f"BEDROCK_STR: {bedrock_str}")
modelId = 'global.anthropic.claude-opus-4-5-20251101-v1:0'
bodyprompt = {
"anthropic_version": "bedrock-2023-05-31",
"max_tokens": 4000,
"top_k": 250,
"top_p": 1,
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"stop_sequences": ["Command:"]
}
response = bedrock_runtime.invoke_model(body=bedrock_str, modelId=modelId, accept='application/json', contentType='application/json')
# response = bedrock_runtime.invoke_model(body= json.dumps(bodyprompt), modelId=modelId, accept='application/json', contentType='application/json')
response_body = json.loads(response.get('body').read())
print(response_body)
return {'statusCode': 200, 'body': json.dumps(response_body)}
Note: Replace region_name with your AWS Region and endpoint_url with the endpoint for Amazon Bedrock.