Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

754
Vistas
AWS Fargate - How to get the public ip address of task by using python boto3

I am creating new fargate task by using the following python script.

import boto3
import json


def handler():
  client = boto3.client('ecs')
  response = client.run_task(
  cluster='fargate-learning', # name of the cluster
  launchType = 'FARGATE',
  taskDefinition='fargate-learning:1', # replace with your task definition name and revision
  count = 1,
  platformVersion='LATEST',
  networkConfiguration={
        'awsvpcConfiguration': {
            'subnets': [
                'subnet-0a024d8ac87668b64', # replace with your public subnet or a private with NAT
            ],
            'assignPublicIp': 'ENABLED'
        }
    })

  print(response)
  return str(response)


if __name__ == '__main__':
    handler()

And here is the response I am getting from boto3.

https://jsonblob.com/5faf3ae6-bc31-11ea-8cae-53bd90c38587

I can not see the public ip address in response although the script is assigning the public ip address and I can see it on website.

aws fargate ip address

So, how can I get this public ip address by using boto3?

Thanks

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This can be done in two steps:

  1. Use describe_tasks to get ENI id associated with your fargate awsvpc interface. The value of eni, e.g. eni-0c866df3faf8408d0, will be given in attachments and details from the result of the call.

  2. Once you have the eni, then you can use EC2.NetworkInterface. For example:

eni_id = 'eni-0c866df3faf8408d0' # from step 1

eni = boto3.resource('ec2').NetworkInterface(eni_id)

print(eni.association_attribute['PublicIp'])
over 4 years ago · Santiago Trujillo Denunciar

0

Tried implementing @Marcin 's answers as a function. Hope this can be helpful

def get_service_ips(cluster, tasks):
    tasks_detail = ecs.describe_tasks(
        cluster=cluster,
        tasks=tasks
    )
    
    # first get the ENIs
    enis = []
    for task in tasks_detail.get("tasks", []):
        for attachment in task.get("attachments", []):
            for detail in attachment.get("details", []):
                if detail.get("name") == "networkInterfaceId":
                    enis.append(detail.get("value"))
   
    # now the ips
    ips = []
    for eni in enis:
        eni_resource = boto3.resource("ec2").NetworkInterface(eni)
        ips.append(eni_resource.association_attribute.get("PublicIp"))

    return ips

as a gist here.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda