amazon-web-services - AWS ECS : get public IP of the instance container when start task is called

标签 amazon-web-services amazon-ecs

我成功地使用 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/

相关文章:

mysql - 从 Amazon S3 存储桶文件创建/更新 Amazon Athena 表

amazon-web-services - 554 消息被拒绝 : Email address is not verified. 以下身份在区域 US-EAST-2 : someemail@gmail. com 中检查失败

amazon-web-services - 带有 CodeDeploy to ECS 的 AWS CodePipeline 找不到 appspec.yml

amazon-web-services - AWS ECS 异常 Container.image contains invalid char 是什么意思?

amazon-web-services - 使用 CloudFormation 更新而不是替换 ECS 任务定义

amazon-ecs - Terraform 动态 block

amazon-web-services - lambda 是否在内存中保留任何数据?

amazon-web-services - 无法创建AW​​S CodeBuild Webhook

python - 从 S3 Bucket 编辑 base.css 文件