From ae5a33df64d7bc5a2b96b45bec4df466c968eb97 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 10 Apr 2026 13:07:51 -0400 Subject: [PATCH 1/2] perf(aws): speed up aws_profiles by parsing config files directly Parse ~/.aws/config and ~/.aws/credentials directly instead of invoking `aws configure list-profiles`, which has significant startup overhead due to the Python-based AWS CLI. Only [default] and [profile NAME] sections are matched, filtering out [sso-session ...], [services ...], and other non-profile sections. Falls back to AWS CLI if neither file is readable. Co-Authored-By: Claude --- plugins/aws/aws.plugin.zsh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index 0c43031df..e6771a143 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -239,9 +239,31 @@ function aws_regions() { } function aws_profiles() { - aws --no-cli-pager configure list-profiles 2> /dev/null && return - [[ -r "${AWS_CONFIG_FILE:-$HOME/.aws/config}" ]] || return 1 - grep --color=never -Eo '\[.*\]' "${AWS_CONFIG_FILE:-$HOME/.aws/config}" | sed -E 's/^[[:space:]]*\[(profile)?[[:space:]]*([^[:space:]]+)\][[:space:]]*$/\2/g' + local config_file="${AWS_CONFIG_FILE:-$HOME/.aws/config}" + local credentials_file="${AWS_SHARED_CREDENTIALS_FILE:-$HOME/.aws/credentials}" + local profiles=() + + # Parse config file: only match [default] and [profile ...] sections, + # skipping [sso-session ...], [services ...], and other non-profile sections + if [[ -r "$config_file" ]]; then + profiles+=($(grep --color=never -E '^\[[ ]*(default|profile[ ]+)' "$config_file" \ + | sed -nE 's/^\[[ ]*(profile[ ]+)?([^]]+[^ ])[ ]*\]$/\2/p')) + fi + + # Parse credentials file (profiles have [name] format, no "profile" prefix) + if [[ -r "$credentials_file" ]]; then + profiles+=($(grep --color=never -Eo '\[.*\]' "$credentials_file" \ + | sed -nE 's/^[[:space:]]*\[([^[:space:]]+)[[:space:]]*\]$/\1/p')) + fi + + # Return unique profiles, or fall back to AWS CLI. + # Note: profiles only visible via AWS CLI (e.g. config plugins, SSO) will + # be missed when config files have entries. Intentional for performance. + if [[ ${#profiles[@]} -gt 0 ]]; then + printf '%s\n' "${profiles[@]}" | sort -u + else + aws --no-cli-pager configure list-profiles 2>/dev/null + fi } function _aws_regions() { From b29e4db103d6eb3dafc070f1cb2f75cf1af43329 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 10 Apr 2026 13:07:59 -0400 Subject: [PATCH 2/2] 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. Uses literal string comparison in awk to avoid regex injection from profile names containing metacharacters. Falls back to AWS CLI if the fast method doesn't find a region. Co-Authored-By: Claude --- plugins/aws/aws.plugin.zsh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index e6771a143..a50935f3d 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -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 @@ -266,6 +266,34 @@ 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 + s = $0; sub(/^\[[ ]*/, "", s); sub(/[ ]*\].*/, "", s) + if (profile == "default" ? (s == "default" || s == "profile default") \ + : sub(/^profile[ ]+/, "", s) && s == profile) + in_profile = 1 + } + in_profile && /^[ ]*region[ ]*=/ { sub(/^[ ]*region[ ]*=[ ]*/, ""); sub(/[ ]*$/, ""); 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)) }