From bfd0700a3b99b7cdc115a11c5b6b091ddd888167 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Sun, 21 Apr 2019 22:56:37 +0300 Subject: [PATCH] Refactor AWS-CLI aliases. - Add region alias for configured (profile) region. - Add metadata-region for outputting the region from the EC2 metadata service, moved from .bashrc (no longer exported as AWS_DEFAULT_REGION, not an issue since it could only be used in EC2 instances and not for local use, it was there mainly as a reminder for me). - Add ecr-login instead of a shell alias, works the same. --- .aws/cli/alias | 8 ++++++++ .bashrc | 13 ------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.aws/cli/alias b/.aws/cli/alias index a8aad3d..73962e3 100644 --- a/.aws/cli/alias +++ b/.aws/cli/alias @@ -1,3 +1,11 @@ [toplevel] whoami = sts get-caller-identity +region = configure get region +ecr-login = !$(aws ecr get-login --no-include-email) +metadata-region = !python3 << EOF + from urllib.request import urlopen + import json + response = urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document') + print(json.loads(response.read().decode('utf-8'))['region']) + EOF diff --git a/.bashrc b/.bashrc index 223441a..ecf4a7f 100644 --- a/.bashrc +++ b/.bashrc @@ -67,7 +67,6 @@ alias ansible-local='ansible localhost -c local -i localhost,' alias ansible-local-playbook='ansible-playbook -i localhost, -c local' alias concat="perl -pe 's/\\n/\\\\n/g'" alias deconcat="perl -pe 's/\\\\n/\\n/g'" -alias ecr-login='eval $(aws ecr get-login --no-include-email)' alias hostlocal='docker run --rm --privileged --net=host gliderlabs/hostlocal' alias cadvisor='docker run --rm --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest' alias apt-daily="monitor __apt-daily" @@ -173,18 +172,6 @@ cyan () { printf '\e[0m' || true } -deduce_aws_region () { - AWS_DEFAULT_REGION="$(python3 << EOF -from urllib.request import urlopen -import json -response = urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document') -print(json.loads(response.read().decode('utf-8'))['region']) -EOF - )" - export AWS_DEFAULT_REGION - echo "$AWS_DEFAULT_REGION" -} - ssh_keyscan_add () { ssh-keyscan "$@" >> "$HOME/.ssh/known_hosts" sort -uo "$HOME/.ssh/known_hosts" "$HOME/.ssh/known_hosts" -- GitLab