gpt4 book ai didi

c# - 通过 C# 客户端 SDK 启动或运行 ECS 或 Fargate 任务

转载 作者:行者123 更新时间:2023-12-05 06:26:53 25 4
gpt4 key购买 nike

我正在尝试在 ECS 中运行或启动现有任务定义,但缺少文档,而且我似乎无法在线找到任何示例。我碰壁了,我想知道是否还有其他人做过类似的事情。

我正在使用 AWSSDK.ECS 包。

var request = JsonConvert.DeserializeObject<Request>(record.Sns.Message);

var task = new RunTaskRequest
{
Count = 1,
NetworkConfiguration = new NetworkConfiguration
{
AwsvpcConfiguration = new AwsVpcConfiguration
{
Subnets = new List<string>() { request.SubnetId},
SecurityGroups = new List<string>() { request.SecurityGroupId},
AssignPublicIp = AssignPublicIp.DISABLED
}
},
Cluster = request.Cluster,
LaunchType = LaunchType.FARGATE,
Overrides = new TaskOverride
{
ContainerOverrides = new List<ContainerOverride>
{
new ContainerOverride
{
Name = request.ContainerName,
Environment = request.EnvironmentVariables
.Select(kvp => new Amazon.ECS.Model.KeyValuePair()
{
Name = kvp.Key,
Value = kvp.Value
}).ToList()
}
}
},
TaskDefinition = request.TaskDefinitionUri
};

await new AmazonEcsClient().RunTaskAsync(task);

最佳答案

检查您的任务定义。如果 NetworkModeawsvpc,那么您必须提供 NetworkConfiguration 参数。这对我有用:

var runTaskRequest = new ECSModel.RunTaskRequest
{
Cluster = "cluster-name",
Count = 1,
LaunchType = LaunchType.FARGATE,
TaskDefinition = "task-definition",
NetworkConfiguration = new ECSModel.NetworkConfiguration
{
AwsvpcConfiguration = new ECSModel.AwsVpcConfiguration
{
SecurityGroups = new List<string> { "security-group" },
Subnets = new List<string> { "subnet" }
}
},
Overrides = new ECSModel.TaskOverride
{
ContainerOverrides = new List<ECSModel.ContainerOverride>
{
new ECSModel.ContainerOverride
{
Name = "container-name",
Command = new List<string>
{
// In case if you need to pass parameters to your instance:
"parameter-one", "parameter-two", "etc"
}
}
}
}
};

await new AmazonEcsClient().RunTaskAsync(runTaskRequest);

关于c# - 通过 C# 客户端 SDK 启动或运行 ECS 或 Fargate 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55731413/

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