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

demandé il y a 2 ans1966 vues
2 réponses
1
Réponse acceptée

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
EXPERT
répondu il y a 2 ans
  • 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.

répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions