gpt4 book ai didi

amazon-web-services - 如何使用 CloudFormation 在现有 EC2 实例上启动容器?

转载 作者:行者123 更新时间:2023-12-04 08:00:46 25 4
gpt4 key购买 nike

场景如下:我有 3 个 EC2 实例(A、B 和 C),全部运行 ECS 优化的 AMI。我想编写一个带有任务定义的 CloudFormation 模板,让该任务仅在 A 上运行。我该怎么做?

我见过的所有 CloudFormation 示例都需要创建新的 EC2 实例,这不是我想要的。

最佳答案

将任务固定到主机的唯一方法是通过 AWS CLI 使用 start-task 来完成:http://docs.aws.amazon.com/cli/latest/reference/ecs/start-task.html

对于通过 Cloudformation 运行 ECS 任务,在 CFT 模板范围内创建并启动所有任务的唯一方法是创建服务。这是未经测试的 CFT 模板:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Curator runner",
"Parameters": {
"CpuUnits": {
"Type": "Number",
"Default": 0,
"Description": "The number of CPU Units to allocate."
},
"Memory": {
"Type": "Number",
"Default": 256,
"Description": "The amount of Memory (MB) to allocate."
},
"ClusterName": {
"Type": "String",
"Description": "The cluster to run the ecs tasks on."
},
"DockerImageUrl": {
"Type": "String",
"Description": "The URL for the docker image. Example: 354500939573.dkr.ecr.us-east-1.amazonaws.com/something:latest"
}
},
"Resources": {
"SomeTask": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [{
"Memory": {
"Ref": "Memory"
},
"Name": "something",
"Image": {
"Ref": "DockerImageUrl"
},
"Cpu": {
"Ref": "CpuUnits"
}
}],
"Volumes": []
}
},
"service": {
"Type": "AWS::ECS::Service",
"Properties": {
"Cluster": {
"Ref": "ClusterName"
},
"DesiredCount": "1",
"TaskDefinition": {
"Ref": "SomeTask"
}
}
}
}
}

关于amazon-web-services - 如何使用 CloudFormation 在现有 EC2 实例上启动容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com