From e28579d0e842644781da4b1311a42f439ce73d3e Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Mon, 3 Jul 2017 12:07:45 +0300 Subject: [PATCH] - Don't parse JSON with regular expressions. --- .bashrc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.bashrc b/.bashrc index 67473bf..5e58b2b 100644 --- a/.bashrc +++ b/.bashrc @@ -104,9 +104,16 @@ alias transmission-remote='ssh -fNo ExitOnForwardFailure=yes xbmc.shore.co.il && alias kpcli='kpcli --kdb ~/Documents/Database.kdbx' deduce_aws_region () { - AWS_DEFAULT_REGION="$(curl --silent \ - http://169.254.169.254/latest/dynamic/instance-identity/document \ - | sed -n 's/ *"region" : "\([a-z0-9\-]*\)"/\1/gp')" + AWS_DEFAULT_REGION="$(python << EOF +from __future__ import print_function +try: + from urllib import urlopen +except ImportError: + from urllib.request import urlopen +import json +print(json.load(urlopen('http://169.254.169.254/latest/dynamic/instance-identity/document'))['region']) +EOF + )" export AWS_DEFAULT_REGION echo "$AWS_DEFAULT_REGION" } -- GitLab