mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-30 02:44:42 +01:00
perf(aws): speed up asp region lookup by parsing config file directly
Add `_aws_get_profile_region` helper that parses ~/.aws/config directly instead of invoking `aws configure get region`, which has significant startup overhead due to the Python-based AWS CLI. Falls back to AWS CLI if the fast method doesn't find a region. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6f27d734c8
commit
b3fe6c2880
1 changed files with 23 additions and 1 deletions
|
|
@ -42,7 +42,7 @@ function asp() {
|
|||
export AWS_PROFILE=$1
|
||||
export AWS_EB_PROFILE=$1
|
||||
|
||||
export AWS_PROFILE_REGION=$(aws configure get region)
|
||||
export AWS_PROFILE_REGION=$(_aws_get_profile_region "$1")
|
||||
|
||||
_aws_update_state
|
||||
|
||||
|
|
@ -265,6 +265,28 @@ function aws_profiles() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Fast region lookup by parsing config file directly, with fallback to AWS CLI
|
||||
function _aws_get_profile_region() {
|
||||
local profile="${1:-$AWS_PROFILE}"
|
||||
local config_file="${AWS_CONFIG_FILE:-$HOME/.aws/config}"
|
||||
local region=""
|
||||
|
||||
# Try fast config file parsing first
|
||||
if [[ -r "$config_file" ]]; then
|
||||
region=$(awk -v profile="$profile" '
|
||||
/^\[/ { in_profile = ($0 ~ "\\[(profile )?[ ]*"profile"[ ]*\\]") }
|
||||
in_profile && /^[ ]*region[ ]*=/ { gsub(/^[ ]*region[ ]*=[ ]*/, ""); gsub(/[ ]*$/, ""); print; exit }
|
||||
' "$config_file")
|
||||
fi
|
||||
|
||||
# Fallback to AWS CLI if fast method didn't find region
|
||||
if [[ -z "$region" ]]; then
|
||||
region=$(aws configure get region --profile "$profile" 2>/dev/null)
|
||||
fi
|
||||
|
||||
echo "$region"
|
||||
}
|
||||
|
||||
function _aws_regions() {
|
||||
reply=($(aws_regions))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue