From ad234f225f7ccd79114cba997bc2d318b1f0b90c Mon Sep 17 00:00:00 2001 From: Andrey Kislyuk Date: Wed, 11 Dec 2019 14:45:10 -0800 Subject: [PATCH] Batch: computeResources.instanceRole is an instance profile It's not an IAM role (the API parameter name in Batch is a misnomer). Validation by matching against known role ARNs will always fail. Scan the known instance profile ARNs instead. --- moto/batch/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/moto/batch/models.py b/moto/batch/models.py index ab52db54c..736b89075 100644 --- a/moto/batch/models.py +++ b/moto/batch/models.py @@ -815,8 +815,10 @@ class BatchBackend(BaseBackend): raise InvalidParameterValueException( "computeResources must contain {0}".format(param) ) - - if self.iam_backend.get_role_by_arn(cr["instanceRole"]) is None: + for profile in self.iam_backend.get_instance_profiles(): + if profile.arn == cr["instanceRole"]: + break + else: raise InvalidParameterValueException( "could not find instanceRole {0}".format(cr["instanceRole"]) )