Skip to content

yggdrasil.aws.batch.resource

resource

AWS Batch runtime — resource + service.

When a job runs under AWS Batch the agent injects a well-known set of env vars (job id, attempt, queue, compute environment, array / multi-node topology). This module exposes them the same way the rest of the AWS surface is shaped:

  • :class:BatchService — the :class:~yggdrasil.aws.client.AWSService binding (service_name == "batch"), so BatchService.current() and client.batch follow the established singleton pattern instead of a free-floating dataclass.
  • :class:AWSBatch — the :class:~yggdrasil.aws.client.AWSResource carrying the captured runtime context, a clickable :attr:explore_url to the job in the Console, and the is_* flags. Reach it as client.batch or AWSBatch.current().

:func:in_aws_environment is the lightweight, network-free "are we running inside AWS?" probe (Batch / ECS / Fargate / Lambda — all set a tell-tale env var); the S3 layer uses it to skip an egress proxy that doesn't apply in-VPC.

AWSBatch

AWSBatch(
    service: Optional[AWSService] = None,
    *,
    env: Optional[Mapping[str, str]] = None
)

Bases: AWSResource

The AWS Batch runtime context this process is running under.

>>> AWSClient.current().batch.is_batch
True
>>> AWSClient.current().batch
AWSBatch(URL('https://eu-west-1.console.aws.amazon.com/batch/home?region=eu-west-1#jobs/detail/abc'))

Off-Batch every field is None and :attr:is_batch is False; the captured env is snapshotted at construction so the resource is stable and picklable.

is_main_node property

is_main_node: bool

True for a single-node job, or the main node of a multi-node job.

explore_url property

explore_url: Optional[URL]

Console deep-link to this Batch job, or None off-Batch.

current classmethod

current(*, env: Optional[Mapping[str, str]] = None) -> 'AWSBatch'

The Batch context for the default client + live process env.

in_aws_environment

in_aws_environment(env: Optional[Mapping[str, str]] = None) -> bool

True when running inside AWS-managed compute (Batch / ECS / Fargate / Lambda). Pure env-var probe — no IMDS round trip.