我正在使用 AWS Batch。我的目标是通过适用于 C++ 的 AWS 开发工具包创建一个多节点并行作业。为此,我按照说明创建了一个作业定义 here .
我正在使用 AWS C++ SDK,我注意到当我尝试覆盖环境变量或命令时,实际上没有任何内容传输到作业。
有趣的是,对于使用普通作业定义(而不是多节点定义)的作业,相同的代码完全可以正常工作:
#include <aws/batch/BatchClient.h>
#include <aws/batch/model/ContainerOverrides.h>
#include <aws/batch/model/KeyValuePair.h>
#include <aws/batch/model/SubmitJobRequest.h>
#include <aws/core/Aws.h>
#include <aws/core/utils/Outcome.h>
int main(void)
{
Aws::SDKOptions options;
Aws::InitAPI(options);
Aws::Batch::BatchClient batchClient;
Aws::Batch::Model::SubmitJobRequest submitJobRequest;
Aws::Batch::Model::SubmitJobOutcome submitJobOutcome;
Aws::Batch::Model::ContainerOverrides containerOverrides;
Aws::Batch::Model::KeyValuePair envVariable;
envVariable.SetName("foo");
envVariable.SetValue("bar");
containerOverrides.AddEnvironment(envVariable); // This does nothing for a multi-node job definition.
containerOverrides.AddCommand("foobarbaz"); // This does nothing for a multi-node job definition.
submitJobRequest.SetJobName("myjob");
submitJobRequest.SetJobDefinition("arn:aws:...."); // This string is an example. I have used the actual job definition ARN.
submitJobRequest.SetJobQueue("arn:aws:...."); // This string is an exmaple. I have used the actual queue ARN.
submitJobRequest.SetContainerOverrides(containerOverrides);
submitJobOutcome = batchClient.SubmitJob(submitJobRequest);
Aws::ShutdownAPI(options);
return 0;
}
我应该为多节点并行作业使用不同的 API 吗?
最佳答案
不要在请求中设置顶级容器覆盖,而是尝试在 node overrides 内部设置容器覆盖。的请求。节点覆盖的向量为 node property override其中包含您的容器覆盖,包括环境变量。在节点属性覆盖中,您需要指定目标节点的名称。
我对 C++ 不是很擅长,所以我无法为您提供确切的代码示例,但是 SDK 正在调用的 API 的 JSON 看起来像这样:
POST /v1/submitjob HTTP/1.1
Content-type: application/json
{
"jobDefinition": "string",
"jobName": "string",
"jobQueue": "string",
"nodeOverrides": {
"nodePropertyOverrides": [
{
"containerOverrides": {
"command": [ "string" ],
"environment": [
{
"name": "string",
"value": "string"
}
],
"instanceType": "string",
"memory": number,
"resourceRequirements": [
{
"type": "string",
"value": "string"
}
],
"vcpus": number
},
"targetNodes": "string"
}
],
"numNodes": number
},
# lots of other stuff
}
希望有帮助。
关于amazon-web-services - 为什么我不能在 AWS Batch C++ SDK 中覆盖多节点并行作业的容器变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56399273/