AWS CDK AWS Batch Construct Library
raw JSON → 1.204.0 verified Mon Apr 27 auth: no python maintenance
The CDK Construct Library for AWS::Batch, enabling you to define and deploy AWS Batch resources (compute environments, job queues, job definitions) as infrastructure as code. Version 1.204.0 is a v1 release (maintenance mode) with monthly cadence. The stable v2 counterpart is 'aws-cdk-lib/aws-batch'.
pip install aws-cdk-aws-batch Common errors
error ModuleNotFoundError: No module named 'aws_cdk_aws_batch' ↓
cause Incorrect import path; the package name uses hyphens, but the import uses underscores.
fix
Use 'from aws_cdk.aws_batch import ...'
error 'module' object has no attribute 'ComputeEnvironment' ↓
cause Trying to use L2 construct in v1; only Cfn* resources exist.
fix
Use CfnComputeEnvironment instead, or upgrade to CDK v2.
error AttributeError: 'list' object has no attribute 'to_string' ↓
cause Misuse of Cfn* property structure; e.g., passing a list where a single value is expected.
fix
Check the CloudFormation resource specification and use the correct Property objects.
Warnings
deprecated aws-cdk-aws-batch v1 is in maintenance mode. No new features, only critical bug fixes. Migrate to v2 for full support. ↓
fix Use 'aws-cdk-lib/aws-batch' with CDK v2.
breaking In v1, only L1 CloudFormation resources (Cfn*) exist. L2 constructs like aws_batch.ComputeEnvironment were introduced in v2. ↓
fix Use Cfn* constructs or migrate to CDK v2 for L2 constructs.
gotcha The pip package name is 'aws-cdk-aws-batch', but the import path is 'aws_cdk.aws_batch' (hyphens become underscores). ↓
fix Import from 'aws_cdk.aws_batch', not 'aws_cdk_aws_batch'.
Imports
- Batch wrong
from aws_cdk_aws_batch import ...correctfrom aws_cdk.aws_batch import CfnComputeEnvironment, CfnJobQueue, CfnJobDefinition - ComputeEnvironment wrong
from aws_cdk.aws_batch import ComputeEnvironmentcorrectfrom aws_cdk.aws_batch import CfnComputeEnvironment
Quickstart
import aws_cdk as cdk
from aws_cdk.aws_batch import CfnComputeEnvironment, CfnJobQueue, CfnJobDefinition
app = cdk.App()
stack = cdk.Stack(app, 'MyBatchStack')
compute_env = CfnComputeEnvironment(stack, 'MyComputeEnv',
type='MANAGED',
service_role='arn:aws:iam::123456789012:role/AWSBatchServiceRole',
compute_resources=CfnComputeEnvironment.ComputeResourcesProperty(
type='EC2',
minv_cpus=0,
maxv_cpus=256,
desiredv_cpus=0,
instance_types=['c5.large'],
subnets=['subnet-12345678'],
security_group_ids=['sg-12345678']
)
)
job_queue = CfnJobQueue(stack, 'MyJobQueue',
job_queue_name='MyQueue',
compute_environment_order=[
CfnJobQueue.ComputeEnvironmentOrderProperty(
compute_environment=compute_env.ref,
order=1
)
]
)
app.synth()