Search code examples
.netamazon-web-servicesaws-sdkamazon-ecsaws-sdk-net

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


I want to start an ECS Task with the AWS .NET SDK. But it throws the following exception:

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

I use the AWS Fargate launch type and the code looks like this:

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);

I can see no way to configure the vpc and subnet. In the AWS Console (Browser) I can specify this when launching the Task manually.

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

How can I add the network configuration to my code?


Update: I looked up v2 of the documentation and the current api version is v3


Solution

  • The RunTaskRequest class has NetworkConfiguration property:

    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.

    It seems that maybe you checked only the constructor.