运行带有容器覆盖的 AWS ECS 任务

huangapple go评论87阅读模式
英文:

aws ecs run ecs task with container overrides

问题

寻求关于在Java应用程序中运行ECS定时任务的帮助!程序正常工作并且在没有覆盖时调用任务。当我们传递覆盖时,它会产生一个错误。是否存在某些问题?

   ListTaskDefinitionFamiliesRequest request = new ListTaskDefinitionFamiliesRequest();
		ListTaskDefinitionFamiliesResult response = client.listTaskDefinitionFamilies(request);
		List<String> ls = response.getFamilies();
		    String cmd[] ={"arg1","arg2"};
		    List<String> command = Arrays.asList(cmd);
		    TaskOverride overrides = new TaskOverride();
		    ContainerOverride containerOverrides = new ContainerOverride();
		    containerOverrides.setCommand(command);
		    overrides.withContainerOverrides(containerOverrides);
		    String subnets[] ={"subnet-bbb","subnet-ccc"};
		    List<String> subnetList = Arrays.asList(subnets);
		    String securityGrp[] ={"sg-xxx"};
		    List<String> securityGrpList = Arrays.asList(securityGrp	);
		    AwsVpcConfiguration awsvpcConfiguration = new AwsVpcConfiguration();
		    awsvpcConfiguration.setSubnets(subnetList);
		    awsvpcConfiguration.setSecurityGroups(securityGrpList);
		    NetworkConfiguration networkConfiguration = new NetworkConfiguration();
		    networkConfiguration.setAwsvpcConfiguration(awsvpcConfiguration);
		RunTaskRequest request = new RunTaskRequest()
				.withCluster("cluster-ecs")
				.withTaskDefinition("task:1")
				.withCount(1)
				.withLaunchType("FARGATE")				
				.withNetworkConfiguration(networkConfiguration)
				.withOverrides(overrides);
		RunTaskResult response = client.runTask(request);
英文:

Looking for help on a java app to run ECS scheduled task! the program works fine and invokes the task without the overrides. when we pass overrides it gives an error. is there some issue?

   ListTaskDefinitionFamiliesRequest request = new ListTaskDefinitionFamiliesRequest();
		ListTaskDefinitionFamiliesResult response = client.listTaskDefinitionFamilies(request);
		List&lt;String&gt; ls = response.getFamilies();
		    String cmd[] ={&quot;arg1&quot;,&quot;arg2&quot;};
		    List&lt;String&gt; command = Arrays.asList(cmd);
		    TaskOverride overrides = new TaskOverride();
		    ContainerOverride containerOverrides = new ContainerOverride();
		    containerOverrides.setCommand(command);
		    overrides.withContainerOverrides(containerOverrides);
		    String subnets[] ={&quot;subnet-bbb&quot;,&quot;subnet-ccc&quot;};
		    List&lt;String&gt; subnetList = Arrays.asList(subnets);
		    String securityGrp[] ={&quot;sg-xxx&quot;};
		    List&lt;String&gt; securityGrpList = Arrays.asList(securityGrp	);
		    AwsVpcConfiguration awsvpcConfiguration = new AwsVpcConfiguration();
		    awsvpcConfiguration.setSubnets(subnetList);
		    awsvpcConfiguration.setSecurityGroups(securityGrpList);
		    NetworkConfiguration networkConfiguration = new NetworkConfiguration();
		    networkConfiguration.setAwsvpcConfiguration(awsvpcConfiguration);
		RunTaskRequest request = new RunTaskRequest()
				.withCluster(&quot;cluster-ecs&quot;)
				.withTaskDefinition(&quot;task:1&quot;)
				.withCount(1)
				.withLaunchType(&quot;FARGATE&quot;)				
				.withNetworkConfiguration(networkConfiguration);
				.withOverrides(overrides);
		RunTaskResult response = client.runTask(request);	

</details>


# 答案1
**得分**: 1

容器名称是覆盖中的必填字段。现在全部设置好了。

containerOverrides.setName("blabla");
containerOverrides.setCommand(command);

<details>
<summary>英文:</summary>

container name is required field in overrides. all set now.

    		    containerOverrides.setName(&quot;blabla&quot;);
		    containerOverrides.setCommand(command);

</details>



huangapple
  • 本文由 发表于 2020年7月28日 22:32:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63136558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定