aws-login-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

aws-login CLI

aws-login CLI

Commands

命令

Login with account and role (recommended)

使用账户和角色登录(推荐)

bash
undefined
bash
undefined

Two positional args: <account> <role>

两个位置参数:<account> <role>

aws-login myaccount admin aws-login 123456789012 ReadOnly
aws-login myaccount admin aws-login 123456789012 ReadOnly

Or with flags

也可使用参数标识

aws-login --account myaccount --role admin
undefined
aws-login --account myaccount --role admin
undefined

Login with a named profile

使用命名配置文件登录

bash
aws-login --profile dev
bash
aws-login --profile dev

Interactive login (prompts for account and role)

交互式登录(会提示输入账户和角色)

bash
aws-login
bash
aws-login

Export credentials to current shell

导出凭证到当前shell

bash
eval "$(aws-login --print-env myaccount admin)"
bash
eval "$(aws-login --print-env myaccount admin)"

Export AWS_PROFILE to current shell

导出AWS_PROFILE到当前shell

bash
eval "$(aws-login --set-profile myaccount admin)"
bash
eval "$(aws-login --set-profile myaccount admin)"

Health check and auto-repair

健康检查与自动修复

bash
aws-login doctor
bash
aws-login doctor

Print version

打印版本号

bash
aws-login --version
bash
aws-login --version

All Flags

所有参数

FlagDescription
--account <id|name>
Account name or ID (alternative to first positional arg)
--role <name>
Role name (alternative to second positional arg)
--profile <name>
Use a specific AWS profile name instead of auto-generated
--sso-session <name>
AWS SSO session name
--region <region>
AWS region override
--kube-context <name>
Switch to this context and save as account default
--no-kube
Skip Kubernetes context switching
--non-interactive
Fail instead of prompting (for CI/scripts)
--print-env
Print full credential export statements to stdout
--set-profile
Print
export AWS_PROFILE=<name>
to stdout
--doctor
Validate and repair AWS/Kubernetes config files
--version
,
-v
Print version
参数说明
--account <id|name>
账户名称或ID(第一个位置参数的替代形式)
--role <name>
角色名称(第二个位置参数的替代形式)
--profile <name>
使用指定的AWS配置文件名,而非自动生成的名称
--sso-session <name>
AWS SSO会话名称
--region <region>
覆盖默认AWS区域
--kube-context <name>
切换到指定上下文,并保存为该账户的默认配置
--no-kube
跳过Kubernetes上下文切换步骤
--non-interactive
无交互模式,遇到需要输入的场景直接报错(适用于CI/脚本)
--print-env
将完整的凭证导出语句打印到标准输出
--set-profile
export AWS_PROFILE=<name>
语句打印到标准输出
--doctor
校验并修复AWS/Kubernetes配置文件
--version
,
-v
打印版本号

Positional Arguments

位置参数

aws-login <account> [role]
  • First positional arg: Account name or ID (same as
    --account
    )
  • Second positional arg: Role name (same as
    --role
    )
  • Positional args cannot be combined with their flag equivalents
aws-login <account> [role]
  • 第一个位置参数:账户名称或ID,和
    --account
    作用一致
  • 第二个位置参数:角色名称,和
    --role
    作用一致
  • 位置参数不能和对应的标识参数同时使用

Non-Interactive / Scripting Usage

非交互/脚本使用场景

For automation and scripts, use
--non-interactive
to prevent prompts:
bash
aws-login --non-interactive --account 123456789012 --role admin
Or with positional args:
bash
aws-login --non-interactive 123456789012 admin
针对自动化和脚本场景,可使用
--non-interactive
参数避免弹出交互提示:
bash
aws-login --non-interactive --account 123456789012 --role admin
也可搭配位置参数使用:
bash
aws-login --non-interactive 123456789012 admin

Profile Naming

配置文件命名规则

When no
--profile
is specified, profiles are auto-named as:
<account-name>-<role>
Example:
prod-admin
如果未指定
--profile
参数,配置文件会自动按以下规则命名:
<account-name>-<role>
示例:
prod-admin

Shell Integration

Shell集成

Run once to install the shell wrapper:
bash
aws-login --install
This updates your shell rc files (
.bashrc
,
.zshrc
,
.zprofile
,
config.fish
) to automatically load an
aws-login
wrapper that sets
AWS_PROFILE
in your current shell after login. No
eval
needed.
To remove:
bash
aws-login --uninstall
执行一次以下命令即可安装shell包装器:
bash
aws-login --install
该命令会更新你的shell rc文件(
.bashrc
.zshrc
.zshrc
.zprofile
config.fish
),自动加载
aws-login
包装器,登录后会自动在当前shell中设置
AWS_PROFILE
,无需手动执行
eval
如需移除集成,执行:
bash
aws-login --uninstall

Kubernetes Integration

Kubernetes集成

After login,
aws-login
automatically:
  1. Lists EKS clusters for the selected account
  2. Updates kubeconfig for each cluster
  3. Filters contexts to those matching the account (by account ID or cluster name)
  4. If one context matches — switches to it automatically
  5. If multiple contexts match:
    • Checks
      ~/.aws-login/kube-prefs.json
      for a saved preference for this account
    • If a preference exists and is still valid, uses it (logs "Using saved Kubernetes context: …")
    • If no preference (or it is stale), prompts interactively via fuzzy finder and saves the choice for next time
    • In
      --non-interactive
      mode, skips the switch with a warning instead of prompting
  6. --kube-context <name>
    — bypasses discovery, switches directly, and saves as preference
Skip entirely with
--no-kube
. Force a one-time context with
--kube-context
.
Preferences are stored per account ID in
~/.aws-login/kube-prefs.json
.
登录完成后,
aws-login
会自动执行以下操作:
  1. 列出所选账户下的EKS集群
  2. 为每个集群更新kubeconfig
  3. 筛选出和当前账户匹配的上下文(按账户ID或集群名称匹配)
  4. 如果仅匹配到一个上下文 —— 自动切换到该上下文
  5. 如果匹配到多个上下文
    • 检查
      ~/.aws-login/kube-prefs.json
      中是否保存了该账户的上下文偏好
    • 如果存在有效偏好,直接使用该偏好(会打印日志「使用已保存的Kubernetes上下文:…」)
    • 如果无有效偏好,会通过模糊搜索弹窗提示选择,同时保存选择供下次使用
    • --non-interactive
      模式下,不会弹出提示,直接跳过上下文切换并输出警告
  6. --kube-context <name>
    —— 跳过自动发现逻辑,直接切换到指定上下文,并保存为偏好配置
可通过
--no-kube
参数完全跳过Kubernetes集成步骤,也可通过
--kube-context
强制指定本次使用的上下文。
上下文偏好会按账户ID保存在
~/.aws-login/kube-prefs.json
文件中。

Requirements

依赖要求

  • AWS CLI v2 (
    aws
    ) with SSO support
  • kubectl
    for Kubernetes context automation (optional)
  • 支持SSO功能的AWS CLI v2(
    aws
    命令)
  • 如需使用Kubernetes上下文自动化功能,需安装
    kubectl
    (可选)

Examples for AI Agents

给AI Agent的使用示例

bash
undefined
bash
undefined

Log in to a specific account and role

登录到指定账户和角色

aws-login --non-interactive --account prod --role admin --no-kube
aws-login --non-interactive --account prod --role admin --no-kube

Log in and set AWS_PROFILE in the environment

登录并在环境变量中设置AWS_PROFILE

eval "$(aws-login --set-profile --non-interactive --account 123456789012 --role ReadOnly)"
eval "$(aws-login --set-profile --non-interactive --account 123456789012 --role ReadOnly)"

Log in and export full credentials

登录并导出完整凭证

eval "$(aws-login --print-env --non-interactive --account staging --role developer)"
eval "$(aws-login --print-env --non-interactive --account staging --role developer)"

Use a named profile

使用命名配置文件登录

aws-login --non-interactive --profile my-dev-profile
aws-login --non-interactive --profile my-dev-profile

Check health

健康检查

aws-login doctor
undefined
aws-login doctor
undefined