Skip to content

Instantly share code, notes, and snippets.

@MooreDerek
Created November 5, 2019 22:58
Show Gist options
  • Save MooreDerek/6fb37560305aa4519d161b33ba8f301c to your computer and use it in GitHub Desktop.
Save MooreDerek/6fb37560305aa4519d161b33ba8f301c to your computer and use it in GitHub Desktop.
Get the Public IP for a Fargate task
CLUSTER=<cluster>
SERVCICE=<service>
# Make sure that the Fargate has aactually started
aws ecs wait services-stable --cluster ${CLUSTER} --services ${SERVICE}
TASK_ARN=`aws ecs list-tasks --cluster ${CLUSTER} --service-name ${SERVICE} | jq -r '.taskArns[] '`
ENI_ID=`aws ecs describe-tasks --cluster ${CLUSTER} --task "${TASK_ARN}" | \
jq -r '.tasks[] | .attachments[] | .details[] | select(.name=="networkInterfaceId") | .value'`
PUBLIC_IP=`aws ec2 describe-network-interfaces --network-interface-ids ${ENI_ID} | \
jq -r '.NetworkInterfaces[] | .Association | .PublicIp'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment