Skip to content

Commit 2837a1f

Browse files
Batch: Allow using IAM instance profile name when creating compute env
1 parent ec3224f commit 2837a1f

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

moto/batch/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def _validate_compute_resources(self, cr: Dict[str, Any]) -> None:
13441344
"Error executing request, Exception : Instance role is required."
13451345
)
13461346
for profile in self.iam_backend.get_instance_profiles():
1347-
if profile.arn == cr["instanceRole"]:
1347+
if profile.arn == cr["instanceRole"] or profile.name == cr["instanceRole"]:
13481348
break
13491349
else:
13501350
raise InvalidParameterValueException(

tests/test_batch/test_batch_compute_envs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010

1111
@mock_aws
12-
def test_create_managed_compute_environment():
12+
@pytest.mark.parametrize('use_arn_for_instance_role', [True, False])
13+
def test_create_managed_compute_environment(use_arn_for_instance_role):
1314
ec2_client, iam_client, ecs_client, _, batch_client = _get_clients()
1415
_, subnet_id, sg_id, iam_arn = _setup(ec2_client, iam_client)
1516

17+
instance_role = iam_arn.replace("role", "instance-profile") if use_arn_for_instance_role else iam_arn.split("/")[-1]
1618
compute_name = str(uuid4())
1719
resp = batch_client.create_compute_environment(
1820
computeEnvironmentName=compute_name,
@@ -28,7 +30,7 @@ def test_create_managed_compute_environment():
2830
"subnets": [subnet_id],
2931
"securityGroupIds": [sg_id],
3032
"ec2KeyPair": "string",
31-
"instanceRole": iam_arn.replace("role", "instance-profile"),
33+
"instanceRole": instance_role,
3234
"tags": {"string": "string"},
3335
"bidPercentage": 123,
3436
"spotIamFleetRole": "string",

0 commit comments

Comments
 (0)