Skip to content

Container backport #516

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
Jun 16, 2025
Merged

Container backport #516

merged 4 commits into from
Jun 16, 2025

Conversation

nateprewitt
Copy link
Contributor

@nateprewitt nateprewitt commented Jun 13, 2025

Description of changes:
This is a temporary backport of #515 to the release prior to the Python pipeline refactoring that's still in progress.

Testing

The simplest way to test is with the awslabs/amazon-ecs-local-container-endpoints container.

Setup environment and Docker

You'll need to set your active credentials in place of test

export AWS_CONTAINER_CREDENTIALS_FULL_URI="http://localhost/creds" 
docker run --rm -it -p 80:80 -e AWS_ACCESS_KEY_ID=test -e AWS_SECRET_ACCESS_KEY=test -e AWS_SESSION_TOKEN=test amazon/amazon-ecs-local-container-endpoints

test.py

import asyncio

from aws_sdk_bedrock_runtime.client import (
    BedrockRuntimeClient,
    ConverseInput,
)
from aws_sdk_bedrock_runtime.models import Message, ContentBlockText
from aws_sdk_bedrock_runtime.config import Config
from aws_sdk_bedrock_runtime.config import HTTPAuthSchemeResolver, SigV4AuthScheme
from smithy_aws_core.credentials_resolvers.container import ContainerCredentialResolver
from smithy_http.aio.crt import AWSCRTHTTPClient

config=Config(
    endpoint_uri="https://bedrock-runtime.us-east-1.amazonaws.com",
    region="us-east-1",
    aws_credentials_identity_resolver=ContainerCredentialResolver(AWSCRTHTTPClient()),
    http_auth_scheme_resolver=HTTPAuthSchemeResolver(),
    http_auth_schemes={
        "aws.auth#sigv4": SigV4AuthScheme(),
    }
)
client = BedrockRuntimeClient(config=config)

async def test():

    messages = [Message(
        role="user",
        content=[ContentBlockText(value="Create a list of 3 best songs from the 1990s")]
    )]

    resp = await client.converse(ConverseInput(model_id='amazon.titan-text-express-v1', messages=messages))
    print(resp)
    
if __name__ == "__main__":
    asyncio.run(test())

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@nateprewitt nateprewitt marked this pull request as ready for review June 13, 2025 02:42
@nateprewitt nateprewitt requested a review from a team as a code owner June 13, 2025 02:42
Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

I left a couple of comments, but this looks great!

@jonathan343
Copy link
Contributor

Also, we should check if previously fetched credentials aren't expired before fetching new ones

Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

LGTM!

@nateprewitt nateprewitt merged commit 82d49f8 into 0.0.2_release Jun 16, 2025
@nateprewitt nateprewitt deleted the container_backport branch June 16, 2025 19:14
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.

2 participants