CDK for ECS - Subnet and Architecture type

0

HI All

I have 2 questions on how to use CDK to deploy ECS using python.

  1. How do we set subnet on the cluster via CDK? The VPC is straightforward using the vpc parameter, however i could not find the param for subnet.
  2. How do we set the architecture(x64 or ARM), using the CDK ? While creating the task I need to set the architecture to a specific value as I am getting the following error: standard_init_linux.go:228: exec user process caused: exec format error

Thank you for your help.

Regards

질문됨 2년 전1967회 조회
2개 답변
1
수락된 답변

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.

AWS
전문가
답변함 2년 전
  • 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 underlying ecs.CfnTaskDefinition and add the property. The documentation I linked above explains how. See "Modifying the AWS CloudFormation resource behind AWS constructs".

1

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.

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠