aws-login-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseaws-login CLI
aws-login CLI
Commands
命令
Login with account and role (recommended)
使用账户和角色登录(推荐)
bash
undefinedbash
undefinedTwo 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
undefinedaws-login --account myaccount --role admin
undefinedLogin with a named profile
使用命名配置文件登录
bash
aws-login --profile devbash
aws-login --profile devInteractive login (prompts for account and role)
交互式登录(会提示输入账户和角色)
bash
aws-loginbash
aws-loginExport 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 doctorbash
aws-login doctorPrint version
打印版本号
bash
aws-login --versionbash
aws-login --versionAll Flags
所有参数
| Flag | Description |
|---|---|
| Account name or ID (alternative to first positional arg) |
| Role name (alternative to second positional arg) |
| Use a specific AWS profile name instead of auto-generated |
| AWS SSO session name |
| AWS region override |
| Switch to this context and save as account default |
| Skip Kubernetes context switching |
| Fail instead of prompting (for CI/scripts) |
| Print full credential export statements to stdout |
| Print |
| Validate and repair AWS/Kubernetes config files |
| Print version |
| 参数 | 说明 |
|---|---|
| 账户名称或ID(第一个位置参数的替代形式) |
| 角色名称(第二个位置参数的替代形式) |
| 使用指定的AWS配置文件名,而非自动生成的名称 |
| AWS SSO会话名称 |
| 覆盖默认AWS区域 |
| 切换到指定上下文,并保存为该账户的默认配置 |
| 跳过Kubernetes上下文切换步骤 |
| 无交互模式,遇到需要输入的场景直接报错(适用于CI/脚本) |
| 将完整的凭证导出语句打印到标准输出 |
| 将 |
| 校验并修复AWS/Kubernetes配置文件 |
| 打印版本号 |
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 to prevent prompts:
--non-interactivebash
aws-login --non-interactive --account 123456789012 --role adminOr with positional args:
bash
aws-login --non-interactive 123456789012 admin针对自动化和脚本场景,可使用参数避免弹出交互提示:
--non-interactivebash
aws-login --non-interactive --account 123456789012 --role admin也可搭配位置参数使用:
bash
aws-login --non-interactive 123456789012 adminProfile Naming
配置文件命名规则
When no is specified, profiles are auto-named as:
--profile<account-name>-<role>Example:
prod-admin如果未指定参数,配置文件会自动按以下规则命名:
--profile<account-name>-<role>示例:
prod-adminShell Integration
Shell集成
Run once to install the shell wrapper:
bash
aws-login --installThis updates your shell rc files (, , , ) to automatically load an wrapper that sets in your current shell after login. No needed.
.bashrc.zshrc.zprofileconfig.fishaws-loginAWS_PROFILEevalTo remove:
bash
aws-login --uninstall执行一次以下命令即可安装shell包装器:
bash
aws-login --install该命令会更新你的shell rc文件(、、、、),自动加载包装器,登录后会自动在当前shell中设置,无需手动执行。
.bashrc.zshrc.zshrc.zprofileconfig.fishaws-loginAWS_PROFILEeval如需移除集成,执行:
bash
aws-login --uninstallKubernetes Integration
Kubernetes集成
After login, automatically:
aws-login- Lists EKS clusters for the selected account
- Updates kubeconfig for each cluster
- Filters contexts to those matching the account (by account ID or cluster name)
- If one context matches — switches to it automatically
- If multiple contexts match:
- Checks for a saved preference for this account
~/.aws-login/kube-prefs.json - 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 mode, skips the switch with a warning instead of prompting
--non-interactive
- Checks
- — bypasses discovery, switches directly, and saves as preference
--kube-context <name>
Skip entirely with . Force a one-time context with .
--no-kube--kube-contextPreferences are stored per account ID in .
~/.aws-login/kube-prefs.json登录完成后,会自动执行以下操作:
aws-login- 列出所选账户下的EKS集群
- 为每个集群更新kubeconfig
- 筛选出和当前账户匹配的上下文(按账户ID或集群名称匹配)
- 如果仅匹配到一个上下文 —— 自动切换到该上下文
- 如果匹配到多个上下文:
- 检查中是否保存了该账户的上下文偏好
~/.aws-login/kube-prefs.json - 如果存在有效偏好,直接使用该偏好(会打印日志「使用已保存的Kubernetes上下文:…」)
- 如果无有效偏好,会通过模糊搜索弹窗提示选择,同时保存选择供下次使用
- 在模式下,不会弹出提示,直接跳过上下文切换并输出警告
--non-interactive
- 检查
- —— 跳过自动发现逻辑,直接切换到指定上下文,并保存为偏好配置
--kube-context <name>
可通过参数完全跳过Kubernetes集成步骤,也可通过强制指定本次使用的上下文。
--no-kube--kube-context上下文偏好会按账户ID保存在文件中。
~/.aws-login/kube-prefs.jsonRequirements
依赖要求
- AWS CLI v2 () with SSO support
aws - for Kubernetes context automation (optional)
kubectl
- 支持SSO功能的AWS CLI v2(命令)
aws - 如需使用Kubernetes上下文自动化功能,需安装(可选)
kubectl
Examples for AI Agents
给AI Agent的使用示例
bash
undefinedbash
undefinedLog 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
undefinedaws-login doctor
undefined