- Newest
- Most votes
- Most comments
You can specify specific subnets for your EC2 container instances and/or your AWSVPC network configuration (if you are using Fargate or AWSVPC networking for your tasks/services).
For EC2 instances, the options you can pass to add_capacity
(for EC2) are here - you want the vpc_subnets
property.
For task networking, you can specify VPC subnets by specifying the vpc_subnets
property to your Ec2Service or FargateService declarations.
If you want to run your task on Graviton2 (arm64 architecture), you don't need to declare the architecture of an ECS Task except on Fargate. At this writing, CDK does not yet have Level 2 construct support for architecture configurations in Task Definitions. You would have to use an Escape Hatch to modify the underlying L1 construct (CfnTaskDefinition in particular) to set the runtime_platform
property.
If you're running your task on an EC2 instance, you just need to make sure that the architecture of your EC2 instance matches the architecture of your container image - or, better still, create a multi-architecture container image.
Hi Michael,
Thanks a bunch for your help. I was able to resolve this.
For everyone else:
runtime_platform_property = _ecs.CfnTaskDefinition.RuntimePlatformProperty(
cpu_architecture="ARM64",
operating_system_family="LINUX"
)
cfn_task_defn = task_definition.node.default_child
cfn_task_defn.runtime_platform = runtime_platform_property
Thank you.
Relevant content
- asked a year ago
- asked 2 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
HI Michael
Thank you for the response.
"You don't need to declare the architecture of an ECS Task except on Fargate. "
Regarding the above mentioned line, what I understand is that instead of using the ecs.FargateTaskDefinition, I should be using the ecs.CfnTaskDefinition. Is that what I understand ?
Here is what I am currently using: task_definition = _ecs.FargateTaskDefinition(self, "TaskDefinition", cpu=2048, memory_limit_mib=4096, execution_role=ecs_role, task_role = ecs_role, )
Thanks
Thanks
You can still use
ecs.FargateTaskDefinition
, but you'll need to use the escape hatch to get to the underlyingecs.CfnTaskDefinition
and add the property. The documentation I linked above explains how. See "Modifying the AWS CloudFormation resource behind AWS constructs".