Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_batch: cannot set compute_resources in ComputeEnvironment #6850

Closed
ghost opened this issue Mar 19, 2020 · 2 comments
Closed

aws_batch: cannot set compute_resources in ComputeEnvironment #6850

ghost opened this issue Mar 19, 2020 · 2 comments
Assignees
Labels
@aws-cdk/aws-batch Related to AWS Batch cause/python-no-types User mistakes caused by a lack of typing enforced by Python guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. wontfix We have determined that we will not resolve the issue.

Comments

@ghost
Copy link

ghost commented Mar 19, 2020

This code snippet works fine in aws_cdk:1.26 in python:

 compute_resource = batch.ComputeResources(
	 vpc=vpc,
	 vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
	 minv_cpus=0,
	 desiredv_cpus=1,
	 maxv_cpus=2,
	 instance_types=[ec2.InstanceType.of(ec2.InstanceClass.STANDARD5_NVME_DRIVE,ec2.InstanceSize.LARGE)],
	 instance_role=iam.Role.from_role_arn(self,
			 "ecsInstanceRole",
			 role_arn=f"arn:aws:iam::{scope.account}:instance-profile/ecsInstanceRole"),
			 )
compute_env = batch.ComputeEnvironment(self,
       f"{self.stack_name}_ComputeEnv",
       managed=False,
       compute_resources=compute_resource) #--->  **I get error in aws_cdk:1.30 in this line**

But when I update aws_cdk to 1.30 I get the following error:

jsii.errors.JSIIError: Expected a string, got {"$jsii.byref":"@aws-cdk/core.Resource@10068"}

and the problem is on compute_resources=compute_resource line.

@ghost ghost added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 19, 2020
@SomayaB SomayaB added the @aws-cdk/aws-batch Related to AWS Batch label Mar 19, 2020
@rix0rrr rix0rrr added the cause/python-no-types User mistakes caused by a lack of typing enforced by Python label Mar 20, 2020
@iliapolo
Copy link
Contributor

Hi @MostafaFarzane

The problem actually comes from the fact you are passing an iam.Role object to the instance_role property, that now expects a string.

instance_role=iam.Role.from_role_arn(self, 
    "ecsInstanceRole", 
    role_arn=f"arn:aws:iam::{scope.account}:instance-profile/ecsInstanceRole")

This was indeed changed in version 1.28.0.

You can have a look at the instance_role property documentation here.

So instead, simply change to:

# also notice i changed `scope.account` to `self.account` since the `account` attribute exists in the `Stack` object, not the `Construct`.
instance_role=f"arn:aws:iam::{self.account}:instance-profile/ecsInstanceRole" 

These types of problems are common when using dynamic languages like python. We actually have an issue on our plate to add dynamic type validation to mimic the behavior of static languages (where this would fail at compile time).

You are welcome to track it here: aws/jsii#1321

Also, I noticed you use managed=False. Actually, compute resources can only be used for managed compute environments, the fact this worked for you before was actually because of a bug. So, you should use managed=True, otherwise you'll get a validation error during synth:

jsii.errors.JavaScriptError:
  Error: It is not allowed to set computeResources on an AWS unmanaged compute environment
      at ComputeEnvironment.validateProps (/private/var/folders/mb/5zx1h88x2891nhk4qpr6_zc8jcqzm6/T/jsii-kernel-7dNSLl/node_modules/@aws-cdk/aws-batch/lib/compute-environment.js:146:19)
      at new ComputeEnvironment (/private/var/folders/mb/5zx1h88x2891nhk4qpr6_zc8jcqzm6/T/jsii-kernel-7dNSLl/node_modules/@aws-cdk/aws-batch/lib/compute-environment.js:57:14)
      at obj._wrapSandboxCode (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:49)
      at Kernel._wrapSandboxCode (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8301:19)
      at Kernel._create (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:26)
      at Kernel.create (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7585:21)
      at KernelHost.processRequest (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7372:28)
      at KernelHost.run (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7312:14)
      at Immediate.setImmediate [as _onImmediate] (/private/tmp/triage-6850/.env/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7315:37)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)

More details about the bug that caused this and the fix can be found here: #6549

@iliapolo iliapolo added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. labels Mar 22, 2020
@ghost
Copy link
Author

ghost commented Mar 23, 2020

@iliapolo Thanks for the response.
With applying the changes you mentioned, now it is working.

@ghost ghost closed this as completed Mar 23, 2020
@rix0rrr rix0rrr added the wontfix We have determined that we will not resolve the issue. label Feb 8, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-batch Related to AWS Batch cause/python-no-types User mistakes caused by a lack of typing enforced by Python guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

No branches or pull requests

3 participants