Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions litellm/llms/bedrock/batches/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ def transform_create_batch_request(

# For Bedrock, we need to return a pre-signed request with AWS auth headers
# Use common utility for AWS signing
signing_params: Final = {**optional_params, **litellm_params}
endpoint_url: Final = (
f"https://bedrock.{self._get_aws_region_name(optional_params, model)}.amazonaws.com/model-invocation-job"
f"https://bedrock.{self._get_aws_region_name(signing_params, model)}.amazonaws.com/model-invocation-job"
)
signed_headers, signed_data = self.common_utils.sign_aws_request(
service_name="bedrock",
data=bedrock_request,
endpoint_url=endpoint_url,
optional_params=optional_params,
optional_params=signing_params,
method="POST",
)

Expand Down
29 changes: 29 additions & 0 deletions tests/test_litellm/llms/bedrock/batches/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,35 @@ def test_create_request_builds_s3_input_output_and_arn(config):
assert result["headers"] == {"Authorization": "signed"}


def test_create_request_forwards_cross_account_aws_auth_from_litellm_params_to_signer(
config,
):
with patch.object(
config.common_utils,
"generate_unique_job_name",
return_value="litellm-batch-1",
), patch.object(config.common_utils, "sign_aws_request") as mock_sign:
mock_sign.return_value = ({}, b"{}")
config.transform_create_batch_request(
model="m",
create_batch_data={"input_file_id": "s3://b/in.jsonl"},
optional_params={},
litellm_params={
"aws_batch_role_arn": "arn:aws:iam::999999999999:role/cross-account-batch-role",
"aws_role_name": "arn:aws:iam::999999999999:role/cross-account-assume-role",
"aws_region_name": "eu-west-1",
},
)
signing_params = mock_sign.call_args.kwargs["optional_params"]
assert (
signing_params["aws_role_name"]
== "arn:aws:iam::999999999999:role/cross-account-assume-role"
)
assert mock_sign.call_args.kwargs["endpoint_url"] == (
"https://bedrock.eu-west-1.amazonaws.com/model-invocation-job"
)


def test_create_request_defaults_output_bucket_to_input_bucket(config):
with patch.object(
config.common_utils,
Expand Down
Loading