AWS .NET SDK 运行 ECS 任务 - 如何 select VPC?

AWS .NET SDK run ECS Task - how to select VPC?

我想使用 AWS .NET SDK 启动 ECS 任务。但它抛出以下异常:

"Network Configuration must be provided when networkMode 'awsvpc' is specified."

我使用 AWS Fargate 启动类型,代码如下所示:

var ecsClient = new AmazonECSClient();
var runTaskRequest = new RunTaskRequest() {
    Cluster = "arn:aws:ecs:xxxx:xxx:cluster/xxx-cluster",
    TaskDefinition = "amttask", // uses latest revision,                  
};

await ecsClient.RunTaskAsync(runTaskRequest);

我看不到配置 vpc 和子网的方法。在 AWS 控制台(浏览器)中,我可以在手动启动任务时指定它。

https://docs.aws.amazon.com/sdkfornet/latest/apidocs/items/TECSRunTaskRequestNET45.html

如何将网络配置添加到我的代码中?


更新:我查阅了文档的 v2,当前 api 版本是 v3

RunTaskRequest class 有 NetworkConfiguration 属性:

The network configuration for the task. This parameter is required for task definitions that use the awsvpc network mode to receive their own elastic network interface, and it is not supported for other network modes. For more information, see Task Networking in the Amazon Elastic Container Service Developer Guide.

看来您可能只检查了构造函数。