(batch): Batch Compute on Fargate with CfnComputeEnvironment requires instance_role and instance_types
See original GitHub issueAWS Batch on Fargate does not allow instanceRole and instanceType in the API. However, CDK requires this parameter to be present.
Reproduction Steps
from aws_cdk import aws_iam as iam
from aws_cdk import aws_ecs as ecs
from aws_cdk import aws_batch as batch
class FaultBatchStack(core.Stack):
def __init__(
self,
scope: core.Construct,
construct_id: str,
**kwargs
) -> None:
super().__init__(scope, construct_id, **kwargs)
batch_service_role = iam.Role(
self,
"BatchServiceRole",
assumed_by=iam.ServicePrincipal('batch.amazonaws.com'),
)
batch_service_role.add_managed_policy(iam.ManagedPolicy.from_aws_managed_policy_name("service-role/AWSBatchServiceRole"))
batch_ecs_role = iam.Role(
self,
"BatchFargateRole",
assumed_by=iam.ServicePrincipal('ecs.amazonaws.com'),
)
batch_cfn_compute = batch.CfnComputeEnvironment(
self,
"RdsBatchCompute",
type='MANAGED',
service_role = batch_service_role.role_arn,
compute_resources= batch.CfnComputeEnvironment.ComputeResourcesProperty(
type = 'FARGATE',
maxv_cpus=50,
minv_cpus=0,
# instance_role = batch_ecs_role.role_arn,
# instance_types = ['m5.large'],
subnets = [vpc.private_subnets[0].subnet_id, vpc.private_subnets[1].subnet_id, vpc.private_subnets[2].subnet_id],
security_group_ids=[rds_sec_group_id])
)
The above will fail on synth/diff However, if you uncomment instance_Type and instance_role it will deploy but fail at CFN level.
What did you expect to happen?
Allow Fargate task to get created without need for instance_type or instance_role
What actually happened?
CDK stack deployed but failed in CloudFormation console with
An error occurred (ClientException) when calling the CreateComputeEnvironment operation: Error executing request, Exception : instanceRole is not applicable for Fargate.,
Environment
- CDK CLI Version : 1.77.0 (build a941c53)
- Framework Version:
- Node.js Version: 14.9.0
- OS : mac 10.15.7
- Language (Version): Python 3.8.6
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
CfnComputeEnvironment — AWS Cloud Development Kit ...
In a managed compute environment, AWS Batch manages the capacity and instance types of the compute resources within the environment. This is based...
Read more >Creates an Batch compute environment - Paws
UNMANAGED compute environments can only use EC2 resources. In a managed compute environment, Batch manages the capacity and instance types of the compute...
Read more >awsbatch - Go Packages
AWS Batch is a batch processing tool for efficiently running hundreds of thousands computing jobs in AWS. Batch can dynamically provision different types...
Read more >Can't define 'FARGATE' AWS Batch compute environment ...
ComputeEnvironment is Level 2 construct (high level) and as you pointed out it does not support Fargate. But if you go to Level...
Read more >aws.batch.ComputeEnvironment - Pulumi
The Amazon ECS instance role applied to Amazon EC2 instances in a compute environment. This parameter isn't applicable to jobs running on Fargate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be resolved once we merge https://github.com/aws/aws-cdk/pull/12204.
@nagmesh Thanks for reporting this.
The underlying problem is that the CloudFormation schema says its required at the same time it says it shouldn’t be supplied when using fargate.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-batch-computeenvironment-computeresources.html#cfn-batch-computeenvironment-computeresources-instancerole
We will address it.
In the meantime, you can remove those two properties:
cc @dsudduth