Last active
April 4, 2025 13:30
-
-
Save shivanshs9/dcc9d8fbc3d9d1fccfafec0c5cac03a5 to your computer and use it in GitHub Desktop.
List Env vars from ECS task definitions (Fish shell)
This file contains hidden or 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
set -x CLUSTER_NAME "<ecs cluster>" | |
set SERVICE_ARNS (aws ecs list-services --cluster $CLUSTER_NAME --query "serviceArns[]" --output yaml | yq -r '.[]') | |
function s3arn_to_s3url | |
echo $argv | sed 's|arn:aws:s3:::|s3://|' | |
end | |
for sarn in $SERVICE_ARNS; | |
echo "$sarn" | |
set tarns (aws ecs list-tasks --cluster $CLUSTER_NAME --service-name $sarn --desired-status RUNNING --query "taskArns[]" --output yaml | yq -r '.[]') | |
for tarn in $tarns; | |
set task_def_arn (aws ecs describe-tasks --cluster $CLUSTER_NAME --tasks $tarn --query "tasks[0].taskDefinitionArn" --output text) | |
set tempTaskContainerFile (mktemp) | |
aws ecs describe-task-definition --task-definition $task_def_arn --query "taskDefinition.containerDefinitions[]" --output yaml | yq -r '.[] | select(.name != "log_router")' > $tempTaskContainerFile | |
set envVals (cat $tempTaskContainerFile | yq -r 'with_entries(select(.key | test("environment.*")))') | |
echo "$envVals" | |
if echo "$envVals" | grep "type: s3"; | |
echo -n "Fetching env file from S3..." | |
set localEnvFile (mktemp) | |
set envFileS3 (cat "$tempTaskContainerFile" | yq -r '.environmentFiles[0].value') | |
echo "$envFileS3" | |
set s3Url (s3arn_to_s3url $envFileS3) | |
echo "$s3Url" | |
aws s3 cp $s3Url $localEnvFile | |
cat $localEnvFile | |
end | |
break | |
end | |
end |
Author
shivanshs9
commented
Apr 4, 2025
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment