英文:
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<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);
</details>
# 答案1
**得分**: 1
容器名称是覆盖中的必填字段。现在全部设置好了。
containerOverrides.setName("blabla");
containerOverrides.setCommand(command);
<details>
<summary>英文:</summary>
container name is required field in overrides. all set now.
containerOverrides.setName("blabla");
containerOverrides.setCommand(command);
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论