Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using boto3 session client instead of relying on env credentials file for APIs #43

Open
ventz opened this issue Mar 30, 2024 · 0 comments

Comments

@ventz
Copy link

ventz commented Mar 30, 2024

os.environ['AWS_ACCESS_KEY_ID'] = settings.aws_access_key_id
os.environ['AWS_SECRET_ACCESS_KEY'] = settings.aws_secret_access_key
self.llm = Bedrock(
# Uncomment credentials_profile_name to use a profile defined in ~/.aws/credentials
#credentials_profile_name=os.environ.get("AWS_BEDROCK_PROFILE_NAME", "talkwithhollis"),
region_name=settings.aws_default_region,

Hi,

In some serverless environments (ie: some lambda/fargate/etc) this approach may fail due to the clobbering of path/environment, and tracking it down will be a pain.

You can use the boto3 session to pass an auth object like this:

import boto3

session = boto3.Session(aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
client = session.client("bedrock-runtime", region_name=settings.aws_default_region)

self.llm = BedrockChat(
            client=client,
            model_id=...
            ...
)

Also - note that if you go to BedrockChat (vs current Bedrock), you can utilize some of the new "chat only" models.

The new LangChain loads would be:

from langchain_community.chat_models import BedrockChat
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.output_parsers import StrOutputParser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant