AWS Bedrock - Learning Series - Blog 1

AWS Bedrock - Learning Series - Blog 1

AWS Bedrock Overview and Enable Bedrock

Published Dec 6, 2023

What is AWS Bedrock

Amazon Bedrock is a fully managed service and it is serverless in nature that provides a selection of high-performing foundation models (FMs) from leading AI companies, including AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon itself. The service offers a unified API and a range of features to simplify the development of generative AI applications, making it accessible to a wider range of users without compromising on privacy and security.

Features in AWS Bedrock

  1. Agents for Amazon Bedrock:
    • Facilitates the creation and deployment of fully managed agents capable of executing complex business tasks.
    • Achieves this by dynamically invoking APIs, providing a seamless and efficient process for handling various tasks.
  2. Amazon Bedrock Developer Experience:
    • Simplifies the development process for developers by offering a user-friendly experience.
    • Enables easy collaboration with a diverse range of high-performing foundation models (FMs), providing flexibility in choosing and working with models.
  3. Knowledge Bases for Amazon Bedrock:
    • Allows users to connect foundation models (FMs) to data sources within the managed service.
    • This connection supports retrieval augmented generation (RAG), enhancing the FM's capabilities and making it more knowledgeable about specific domains and organisations.
  4. Amazon Bedrock Security and Compliance:
    • Ensures the development of generative AI applications that adhere to stringent data security and compliance standards.
    • Addresses standards such as GDPR and HIPAA, emphasizing the importance of privacy and compliance in the deployment of AI solutions.

Enable Model Access

Login to AWS Console
Go to Bedrock and Select —> Model Access

Enable Required Model Access

  • Select the Model you need an Access - Submit
  • You have to wait till it list as Access

Enable Logging for Troubleshooting

  • I want to enable logging for Text, Image, Embedding.
  • Like to Select only Cloudwatch logs, You can enable S3 and Cloudwatch Logs Also
  • Provided the Log group Name

Let us Test via AWS CLI

  • Hope you connected with AWS CLI with AccessKey/Secret Credential some Local IDE - Here I am using my Local Laptop with upgraded CLI
  • In case if you use —> Sagemaker Domain —> Launch App —> Studio -> Provide IAM Role (My Next Blog, I can share information on using Bedrock in Sagemaker Studio Notebook)
Upgrade AWS CLI, Boto and Boto-core
% pip install --no-build-isolation --force-reinstall "boto3>=1.28.57" "awscli>=1.29.57" "botocore>=1.31.57"
List Foundation Model Provider - AWS CLI
$ aws bedrock list-foundation-models | grep providerName | sort -u
"providerName": "AI21 Labs",
"providerName": "Amazon",
"providerName": "Anthropic",
"providerName": "Cohere",
"providerName": "Meta",
"providerName": "Stability AI",
List Foundation Models - AWS CLI
aws bedrock list-foundation-models | grep "modelId" | sort -nr | awk '{print $2}' | sed -e 's/,//g'
Invoke a LLM Model - using Bedrock CLI
aws bedrock-runtime invoke-model \
--model-id ai21.j2-ultra-v1 \
--body "{\"prompt\":\"Write a Article about Cricket World Cup 2011\",\"maxTokens\":200,\"temperature\":0.7,\"topP\":1,\"stopSequences\":[],\"countPenalty\":{\"scale\":0},\"presencePenalty\":{\"scale\":0},\"frequencyPenalty\":{\"scale\":0}}" \
--cli-binary-format raw-in-base64-out \
--region us-east-1 \
Explanation for CLI
Parse the Output using jq
$ cat invoke-model-output.txt| jq -r '.completions[].data.text'
The 2011 Cricket World Cup was the tenth edition of the Cricket World Cup, the premier international limited-overs cricket tournament. It was held from 19 February to 2 April 2011 in the Indian subcontinent.
The final was contested between India and Sri Lanka, with India winning by six wickets. India's victory marked the first time they had won the Cricket World Cup in home country.
Stay tuned…. for another blog on AWS Bedrock