我成功地使用 AWS-SDK for node js 启动任务,但此响应不包含启动任务的实例的 IP 地址。
有什么办法可以在同一个回复中检索实例的 IP 吗?
有哪些可能的选择?但是我确实在回复中看到了 containerInstanceArn。
var ecs = new ECS_AWS.ECS({apiVersion: '2014-11-13'});
var params = {
family: 'test-code123',
containerDefinitions: [
{
environment: [],
name: 'simple-app',
image: 'abc/cbuild:2',
cpu: 1024,
memory: 500,
portMappings: [
{
containerPort: 8000,
hostPort: 8000
}
],
command: [
'node',
'/src1/server.js',
'8000'
],
essential: true
}
]
};
ecs.registerTaskDefinition(params, function(err, data) {
if (err) console.log("ECS error" + err + err.stack); // an error occurred
else console.log(data);
创建任务后,我进行 runTask API 调用
var ecs = new ECS_AWS.ECS({apiVersion: '2014-11-13'});
var params = {
taskDefinition: 'arn:aws:ecs:ap-southeast-1:32:task-definition/test-code123:5', /* required */
count: 1,
};
ecs.runTask(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
最佳答案
基于现有的 ECS api,没有直接的 API 来获取任务启动的实例的 IP。
您将需要使用 describeContainerInstances
ecs 的 API 获取实例的物理 id,然后调用 ec2 API 获取启动任务的实例的 IP。
关于amazon-web-services - AWS ECS : get public IP of the instance container when start task is called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37728119/