tools.aws.helpers module
Generic boto3 invoke helper for tools/aws handlers.
- async tools.aws.helpers.aws_method(ctx, service, method, *, region=None, request_json=None)[source]
Invoke an arbitrary boto3
client(service).method(**kwargs)call.Generic escape hatch that lets any AWS tool reach an arbitrary boto3 operation: it resolves the caller’s credentials, decodes the optional
request_jsonpayload into keyword arguments, runs the blocking boto3 call off the event loop, and serialises the result. This is why every per-service JSON tool (ec2, s3, lambda, iam, etc.) can be defined as a thin wrapper rather than hand-coding each API method.Resolves a boto3
Sessionviatools.aws.base._get_session()(which reads the user’s stored AWS key from Redis or falls back toAWS_*env vars), parsesrequest_jsonwithjsonutil.loads(), and executes the nested_runclosure insideasyncio.to_thread()so the network call never stalls the loop. Results are serialised withtools.aws.base._dumps()and failures wrapped bytools.aws.base._err(); missing credentials surfacetools.manage_api_keys.missing_api_key_error(). Any AWS-side mutation depends entirely on whichmethodis requested – it has no Redis, event-bus, KG, or LLM interaction of its own.Called directly by the per-service
stshandlers intools.aws.stsand by the_handlerclosure thatwrap_aws_method()returns for every other AWS service module; also exercised directly intests/test_aws_tools.py.- Parameters:
ctx – The tool
ToolContext(orNone) used to resolve AWS credentials.service (
str) – The boto3 service name to build a client for (e.g.ec2).method (
str) – The client method to invoke on that service (e.g.describe_instances).region (
str|None) – Optional AWS region name; the session default is used whenNone.request_json (
str|None) – Optional JSON string decoded into the keyword arguments passed to the boto3 method.
- Returns:
The JSON-serialized boto3 response on success, or a
{"error": ...}JSON string when credentials are missing, the JSON is invalid, or the API call raises.- Return type:
- tools.aws.helpers.wrap_aws_method(service, method)[source]
Build an async tool handler bound to one boto3
serviceandmethod.Factory that captures a service/method pair and returns an async
_handlerclosure suitable for use as thehandlerof an AWS tool definition. This is what lets eachtools/aws/*module declare dozens of JSON-driven operations declaratively (a list of(name, method, description)tuples) instead of writing a coroutine per API call; the returned closure simply forwards toaws_method()with the captured names.Pure closure construction with no side effects of its own – it touches no Redis, event bus, KG, or LLM; all credential resolution, JSON parsing, the threaded boto3 call, and result/error serialisation happen later inside
aws_method()when the returned handler runs.Called by the per-service tool builders across the
tools/aws/*modules (ec2, s3, lambda, iam, rds, ecs, route53, cloudwatch, sqs, sns, ecr, elbv2, dynamodb, logs, secretsmanager) to populate their tool lists – e.g.wrap_aws_method("ec2", meth)insidetools.aws.ec2._ec2_json_tools().- Parameters:
- Returns:
An async
_handler(request_json=None, region=None, ctx=None) -> strcoroutine function that delegates toaws_method().