I was successful in starting a task using AWS-SDK for node js but this response does not contain the IP address of the instance on which the task was initiated. Is there any way I can retrieve the IP of the instance in the same reply ?
What are the possible options ? However I do see the containerInstanceArn in the reply.
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);
Once the task is created I make a runTask API Call
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
});
Based on the existing ECS apis, there is no direct API to get the IP of the instance where the task started.
You will need to use describeContainerInstances
API of ecs to get the physical id of the instance and then call ec2 APIs to get the IP of the instance where the task was started.