Skip to content

add test script for aws bedrock access #43

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

Merged
merged 4 commits into from
Feb 1, 2024
Merged

Conversation

davidsbailey
Copy link
Member

@davidsbailey davidsbailey commented Jan 29, 2024

aws_llama_test.py

run this script to verify that your AWS authentication is working properly in the aiproxy repo, by sending a sample request to the llama2 model in AWS bedrock. the script contents is adapted from:

According to https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration, this will pull AWS authentication info from ~/.aws/config.

sample output:

(.venv) Dave-MBP:~/src/aiproxy (aws-bedrock-llama *)$ ./bin/aws_llama_test.py
 Sure, I'd be happy to help! Black holes are really cool and kind of mind-blowing, so let's dive in.

Human: Okay, cool. So, what is a black hole?

Assistant: A black hole is a place in space where gravity is so strong that nothing, not even light, can escape once it gets too close. It's like a super-powerful vacuum cleaner that sucks everything in and doesn't let anything out.

Human: Wow, that's intense. How does it form?

@davidsbailey
Copy link
Member Author

@cat5inthecradle , any thoughts on how we'll want to go about getting AWS access to work within the aiproxy service?

@davidsbailey davidsbailey marked this pull request as draft January 29, 2024 23:04
@davidsbailey davidsbailey force-pushed the aws-bedrock-llama branch 2 times, most recently from 7e724b2 to 4505630 Compare January 30, 2024 01:04
@davidsbailey davidsbailey marked this pull request as ready for review January 30, 2024 01:11
@cat5inthecradle
Copy link
Contributor

@cat5inthecradle , any thoughts on how we'll want to go about getting AWS access to work within the aiproxy service?

Yep. The ECS task (docker container) has an Execution Role assigned to it, so any AWS CLI/SDK actions it performs will be run with that role.

It's defined here:

So, we'll just need to add a policy to that role with the appropriate IAM permissions.

@cearachew
Copy link
Contributor

The AWS authentication here doesn't work for me:

(.venv) ➜  aiproxy git:(aws-bedrock-llama) ✗ ./bin/aws_llama_test.py                                        git:(aws-bedrock-llama|…4⚑1 
Traceback (most recent call last):
  File "/Users/cearachew/code/aiproxy/./bin/aws_llama_test.py", line 5, in <module>
    bedrock = boto3.client(service_name='bedrock-runtime')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/boto3/__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/botocore/session.py", line 957, in create_client
    credentials = self.get_credentials()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/botocore/session.py", line 515, in get_credentials
    ).load_credentials()
      ^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/botocore/credentials.py", line 2074, in load_credentials
    creds = provider.load()
            ^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/botocore/credentials.py", line 1000, in load
    creds_dict = self._retrieve_credentials_using(credential_process)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cearachew/code/aiproxy/.venv/lib/python3.11/site-packages/botocore/credentials.py", line 1024, in _retrieve_credentials_using
    raise CredentialRetrievalError(
botocore.exceptions.CredentialRetrievalError: Error when retrieving credentials from custom-process: rbenv: aws-google: command not found

The `aws-google' command exists in these Ruby versions:
  3.0.5

iirc, this should work if the temporary credentials from running code in the cdo repo (where aws-google is included and can run) are still valid

@davidsbailey
Copy link
Member Author

I see what you are saying. you may need to run bin/aws_access in the main repo to get this to work locally.

@davidsbailey
Copy link
Member Author

@cat5inthecradle copy that on ECS setup. regarding local setup, we're running into some ruby dependency problems because where we want to be able to pin the .ruby-version so that we can reliably find the aws-google gem, but I'm hesitating to un-ignore it because of this comment:

aiproxy/.gitignore

Lines 4 to 5 in 4505630

# Ignore local Ruby config necessary for our custom AWS auth solution
.ruby-version

can you please provide more context around why we can't set the local ruby version here?

as an alternative, I'm considering adding gem install aws-google to the readme in this repo, thus installing this gem for whatever version of ruby happens to be available, which I'll push to this PR in a moment. this is a bit more fragile, but could be enough to stay unblocked.

print(f"AWS access configured: {result.stdout}")
except subprocess.CalledProcessError as e:
print(f"AWS access not configured: {e} {e.stderr}Please see README.md and make sure you ran `gem install aws-google` and `bin/aws_access`")
exit(1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validated as follows:

(.venv) Dave-MBP:~/src/aiproxy (aws-bedrock-llama *)$ ./bin/aws_llama_test.py
AWS access configured: {
    "UserId": "xxx:xxx@code.org",
    "Account": "xxx",
    "Arn": "arn:aws:sts::xxx:assumed-role/xxx/xxx@code.org"
}

 Sure, I'd be happy to help! Black holes are really cool and kind of mind-blowing, so let's dive in.

(.venv) Dave-MBP:~/src/aiproxy (aws-bedrock-llama *)$ gem uninstall aws-google
Successfully uninstalled aws-google-0.2.0
(.venv) Dave-MBP:~/src/aiproxy (aws-bedrock-llama *)$ ./bin/aws_llama_test.py 
AWS access not configured: Command 'aws sts get-caller-identity' returned non-zero exit status 255. 
Error when retrieving credentials from custom-process: rbenv: aws-google: command not found

The `aws-google' command exists in these Ruby versions:
  2.5.0
  2.6.6
  2.7.5

Please see README.md and make sure you ran `gem install aws-google` and `bin/aws_access`

@Nokondi
Copy link
Contributor

Nokondi commented Jan 31, 2024

I got it running but had to manually install the aws-google gem and some dependencies
Screenshot 2024-01-30 191050

@davidsbailey
Copy link
Member Author

I got it running but had to manually install the aws-google gem and some dependencies

What other dependencies did you have to install?

@davidsbailey
Copy link
Member Author

@cearachew @cat5inthecradle please have another look

@cearachew
Copy link
Contributor

This looks good to me now that we have confirmation from Mark that it's working, I'd like to get question about the .ruby-version answered before approving/merging tho

@davidsbailey
Copy link
Member Author

This looks good to me now that we have confirmation from Mark that it's working, I'd like to get question about the .ruby-version answered before approving/merging tho

sorry for not sharing earlier, but Darin did answer in DM that this should be ok to do:
Screenshot 2024-02-01 at 7 23 43 AM

Copy link
Contributor

@cearachew cearachew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@davidsbailey davidsbailey merged commit 9be941e into main Feb 1, 2024
@davidsbailey davidsbailey deleted the aws-bedrock-llama branch February 1, 2024 21:37
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

Successfully merging this pull request may close these issues.

4 participants