Last active
January 2, 2021 21:20
-
-
Save fertapric/4ae3a1209e7118c275821ce35512daec to your computer and use it in GitHub Desktop.
Script to extract environment variables from a ECS service
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/sh | |
print_help() { | |
echo "Extract environment variables from an ECS service." | |
echo | |
echo "Usage: $0 [OPTIONS] SERVICE" | |
echo | |
echo "Options:" | |
echo " -h, --help Print usage" | |
} | |
ecs_env() { | |
aws ecs describe-task-definition \ | |
--task-definition "$1-taskdef" \ | |
--region "${AWS_DEFAULT_REGION-eu-west-1}" \ | |
--query "taskDefinition.containerDefinitions[].environment[].[join('=', [name, value])]" \ | |
--output text | |
} | |
case "$1" in | |
"" ) | |
print_help | |
exit 1 | |
;; | |
-h | --help ) | |
print_help | |
;; | |
* ) | |
ecs_env "$@" | |
;; | |
esac |
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/sh | |
print_help() { | |
echo "Extract the Docker image (or images) from an ECS service." | |
echo | |
echo "Usage: ecs-image [OPTIONS] SERVICE" | |
echo | |
echo "Options:" | |
echo " -h, --help Print usage" | |
} | |
ecs_image() { | |
aws ecs describe-task-definition \ | |
--task-definition "$1-taskdef" \ | |
--region "${AWS_DEFAULT_REGION-eu-west-1}" \ | |
--query "taskDefinition.containerDefinitions[].[image]" \ | |
--output text | |
} | |
case "$1" in | |
"" ) | |
print_help | |
exit 1 | |
;; | |
-h | --help ) | |
print_help | |
;; | |
* ) | |
ecs_image "$@" | |
;; | |
esac |
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 | |
print_help() { | |
echo "Run a Docker container with the same image and environment" | |
echo "variables as the given ECS service." | |
echo | |
echo "Usage: ecs-run [OPTIONS] SERVICE [COMMAND]" | |
echo | |
echo "Options:" | |
echo " -h, --help Print usage" | |
} | |
ecs_run() { | |
SERVICE="$1" | |
shift | |
docker run --rm -it --env-file <(ecs-env "${SERVICE}") "$(ecs-image "${SERVICE}")" "$@" | |
} | |
case "$1" in | |
"" ) | |
print_help | |
exit 1 | |
;; | |
-h | --help ) | |
print_help | |
;; | |
* ) | |
ecs_run "$@" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment