AWS Bedrock Summarization of Detailed Technical Reports
A. Prerequisites to practice this tutorial.
- Access to Cohere foundation model in Amazon Bedrock service.
For this you can go to AWS Bedrock -> Bedrock Configurations -> Model Access and see if you have access for Cohere foundation model. If not, then request the access for the same.
B. Create a Lambda function
1. Provide basic information like Function name and Runtime. We can give the name like demoTextSummarization.
- Check the boto3 version, it should be greater than 1.28.63
When you create the Lambda function, in the Lambda code you can use this code to check the boto3 version.
print(boto3.__version__)
- In my test boto3 version is 1.35.145 which is good enough for this tutorial.
C. Provide permissions to IAM role and increase the timeout for Lambda function.
- In the Configuration section click on the Permissions and then click on the Role link.
- In the IAM Role section, click on Add Permissions -> Attach Policies
- Search for Bedrock and attach the policy AmazonBedrockFullAccess
- In the Configuration section, click on General Configuration and then click on Edit button
In the Edit Basic Settings change the timeout to 1 minute and 3 seconds as AWS Bedrock can take some time to get results from Cohere Foundation model.
D. Create Connection with Bedrock and pass inference parameters.
- Import boto3 and create client connection with Bedrock
- Click on Configure Test event in the Test button and add prompt value for a test as follows:
- In Amazon Bedrock, open the left menu and select Text in Playground. Select the Command model and then from right top select three dots and open the API Request to copy the model Id.
- Create the body variable which will be passed as inference parameter to Cohere model.
body = json.dumps( {
"prompt": input_prompt,
"temperature": 0.9,
"p": 0.75,
"k": 0,
"max_tokens": 100
} );
- Convert the response received into bytes and then into String. Then retrieve the value from the string as a final response to be returned from Lambda
E. Create REST API using AWS API Gateway
- Search for API Gateway in AWS Console and click on Create API
- On the next screen click on Build for Rest API
- Name the API as summarizationApi and click on Create API
- Click on Create Resource and give resource a name
- Click on Create Method
- Select the Method Type as POST and select the Lambda function from drop down
- Edit the REST API Method and add query string parameter "prompt" and make it Required.
- Add mapping template information for the prompt parameter.
- Deploy the API and test the API.
- Pass the prompt and check the results
About me: I am an independent technical writer and if you are an organization that want to hire me then I can be contacted at techonlinewriter@gmail.com.
Subscribe to my newsletter
Read articles from Prakash Agrawal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by