Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

744
Views
AWS Fargate: cómo obtener la dirección IP pública de la tarea mediante python boto3

Estoy creando una nueva tarea de Fargate usando la siguiente secuencia de comandos de Python.

 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()

Y aquí está la respuesta que recibo de boto3.

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

No puedo ver la dirección IP pública en respuesta, aunque el script asigna la dirección IP pública y puedo verla en el sitio web.

dirección ip de aws fargate

Entonces, ¿cómo puedo obtener esta dirección IP pública usando boto3?

Gracias

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Esto se puede hacer en dos pasos :

  1. Use describe_tasks para obtener la identificación ENI asociada con su interfaz fargate awsvpc . El valor de eni, por ejemplo, eni-0c866df3faf8408d0 , se dará en attachments y los details del resultado de la llamada.

  2. Una vez que tenga el eni, puede usar EC2.NetworkInterface . Por ejemplo:

 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 Report

0

Intenté implementar las respuestas de @Marcin como una función. Espero que esto puede ser útil

 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

como esenciaaquí .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!