aws / aws/aws-cdk

aws_batch_alpha: Resource names not automatically prepended with stack name

Open
#23,665 5 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-batch bug needs-cfn p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

Normally the names of all resources created by the CDK get prepended with the stack name, which helps a lot identifying the stack the resources belong to. This is not the case for the constructs from the aws_batch_alpha module.

### Expected Behavior

I expected all resources created in my stack to have their names prepended with the stack name somehow.

### Current Behavior

Most resources have their names prepended with the stack name but the ones from aws_batch_alpha don't. See the comments in the code below for examples.

### Reproduction Steps

```python
from typing import Any, cast

from aws_cdk import Stack
from aws_cdk import aws_batch_alpha as batch
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_ecs as ecs
from aws_cdk import aws_iam as iam

from constructs import Construct

class MyCdkStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs: Any) -> None:
super().__init__(scope, construct_id, **kwargs)

# The name of this VPC is MyCdkStack/VPC
vpc = ec2.Vpc(self, "VPC")

# The name of this security group is MyCdkStack-BatchEnvironmentSecurityGroup-
batch_environment_sg = ec2.SecurityGroup(self, "BatchEnvironmentSecurityGroup", vpc=vpc)

# The name of this compute environment is BatchComputeEnvironment-
batch_compute_environment = batch.ComputeEnvironment(
self,
"BatchComputeEnvironment",
compute_resources=batch.ComputeResources(
maxv_cpus=16,
type=batch.ComputeResourceType.FARGATE,
vpc=vpc,
vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
security_groups=[batch_environment_sg],
),
enabled=True,
managed=True,
)

# The name of this job queue is BatchJobQueue-
batch_job_queue = batch.JobQueue(
self,
"BatchJobQueue",
compute_environments=[
batch.JobQueueComputeEnvironment(
compute_environment=batch_compute_environment,
order=1,
)
],
priority=1,
)

# The name of this iam role is already predefined.
task_execution_role = iam.Role.from_role_arn(
self,
"TaskExecutionRole",
f"arn:aws:iam::{self.account}:role/ecsTaskExecutionRole",
mutable=False,
)

# The name of this iam role is MyCdkStack-TaskRole-
task_role = iam.Role(self, "TaskRole", assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"))

# The name of this job definition is BatchJobDefinition-
batch_job_definition = batch.JobDefinition(
self,
"BatchJobDefinition",
container=batch.JobDefinitionContainer(
assign_public_ip=True,
image=ecs.EcrImage.from_registry("docker/whalesay"),
execution_role=task_execution_role,
job_role=cast(iam.IRole, task_role),
vcpus=0.25,
memory_limit_mib=512,
),
platform_capabilities=[batch.PlatformCapabilities.FARGATE],
)
```

### Possible Solution

Automatically prepend their names with the stack name.

### Additional Information/Context

_No response_

### CDK CLI Version

2.60.0 (build 2d40d77)

### Framework Version

_No response_

### Node.js Version

v18.12.1

### OS

Fedora Linux 37

### Language

Python

### Language Version

Python (3.11.1)

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reading the aws_batch_alpha entry points for ComputeEnvironment, JobQueue, and JobDefinition, then compare their generated-name handling with the EC2 constructs shown in the reproduction. Reproduce the stack-name mismatch and inspect or add module tests; done means the Batch resources' names are consistently prefixed with the stack name without breaking existing naming behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.