Last active
April 8, 2024 05:59
-
-
Save schuettc/5e805ec2ca6c21f9b3af3f9cfa75fade to your computer and use it in GitHub Desktop.
ECS Fargate IP Addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
> taskIps.env | |
TASK_LIST=$(aws ecs list-tasks --cluster $CLUSTER_NAME) | |
TASK_ARNS=$(echo "$TASK_LIST" | jq -r '.taskArns[]') | |
while IFS= read -r TASK_ARN; do | |
echo "$TASK_ARN" | |
NETWORK_INTERFACE_ID=$(aws ecs describe-tasks --cluster $CLUSTER_NAME --tasks "$TASK_ARN" --query 'tasks[0].attachments[0].details[?name==`networkInterfaceId`].value' --output text) | |
PRIVATE_IP=$(aws ecs describe-tasks --cluster $CLUSTER_NAME --tasks "$TASK_ARN" --query 'tasks[0].attachments[0].details[?name==`privateIPv4Address`].value' --output text) | |
PUBLIC_IP=$(aws ec2 describe-network-interfaces --network-interface-ids "$NETWORK_INTERFACE_ID" --query 'NetworkInterfaces[*].Association.PublicIp' --output text) | |
TASK_NAME=$(aws ecs describe-tasks --cluster $CLUSTER_NAME --tasks "$TASK_ARN" --query 'tasks[0].containers[0].name' --output text | tr '[:lower:]' '[:upper:]') | |
echo "${TASK_NAME}_PUBLIC_IP=$PUBLIC_IP" >> taskIps.env | |
echo "${TASK_NAME}_PRIVATE_IP=$PRIVATE_IP" >> taskIps.env | |
done <<< "$TASK_ARNS" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment