当前位置: 首页 > 知识库问答 >
问题:

必须删除环境变量,以便aws cli在没有--file标志的情况下工作

周云
2023-03-14

好吧,我对这种行为感到困惑。基本上,当我在环境变量中设置AWS creds related时,每次使用CLI时,AWS CLI都会强制我传递--profile标志。

因此,基本上当AWS\u ACCESS\u KEY\u IDAWS\u SECRET\u ACCESS\u KEY时,即使我的配置文件是[default],我也不能运行像AWS s3 ls这样的命令而不向它传递--profile标志

另外,请注意环境变量值和my/中的值。aws/凭证文件完全相同。此外,我还尝试将AWS_PROFILEAWS_DEFAULT_PROFILE设置为默认值,希望如果在环境变量中设置了keys、secret和PROFILE等所有值,那么我不必显式传递任何--PROFILE标志。在这一点上,不必显式地传递此标志对我来说非常重要,因为如果我正在运行一个与aws连接并获取默认凭据的应用程序,则没有简单的方法将配置文件信息传递给该应用程序。

我的凭据文件如下所示:

[default]
aws_access_key_id = AKIA****
aws_secret_access_key = VpR***

我的配置文件如下所示:

[default]
region = us-west-1
output = json

我的环境变量对于相应的条目具有相同的值。至少用于密钥、机密和配置文件。

有没有办法解决这个问题?

共有1个答案

严高峻
2023-03-14

AWS CLI按特定顺序使用一系列提供程序查找凭据。(https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#config-settings-and-precedence)

明确地:

Command line options – You can specify --region, --output, and --profile as parameters on the command line.

Environment variables – You can store values in the environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN. If they are present, they are used.

CLI credentials file – This is one of the files that is updated when you run the command aws configure. The file is located at ~/.aws/credentials on Linux or macOS, or at C:\Users\USERNAME\.aws\credentials on Windows. This file can contain the credential details for the default profile and any named profiles.

CLI configuration file – This is another file that is updated when you run the command aws configure. The file is located at ~/.aws/config on Linux or macOS, or at C:\Users\USERNAME\.aws\config on Windows. This file contains the configuration settings for the default profile and any named profiles.

Container credentials – You can associate an IAM role with each of your Amazon Elastic Container Service (Amazon ECS) task definitions. Temporary credentials for that role are then available to that task's containers. For more information, see IAM Roles for Tasks in the Amazon Elastic Container Service Developer Guide.

Instance profile credentials – You can associate an IAM role with each of your Amazon Elastic Compute Cloud (Amazon EC2) instances. Temporary credentials for that role are then available to code running in the instance. The credentials are delivered through the Amazon EC2 metadata service. For more information, see IAM Roles for Amazon EC2 in the Amazon EC2 User Guide for Linux Instances and Using Instance Profiles in the IAM User Guide.

另一个可能的选项是取消设置env中的任何冲突变量,并依靠aws凭据文件从默认条目中提供适当的访问凭据。

 类似资料:
  • 我正在建立一个应用程序,并使用MariaDB作为我的数据库。我有一张桌子“kick_votes”。其主键包含三个字段: null

  • 我有一个使用Helm和Kubernetes部署的Python应用程序。我想从main.py中取出硬编码变量,并使它们在helm中可配置。问题是,如果我将它们从main.py中取出,那么我就失去了使用运行代码的能力。那么我就失去了快速测试和迭代的能力,因为我需要为3-4个地方的每个参数维护两个单独的系统。 使用字符串作为环境变量integer,如Helm文档所示。 如果我保持上面的设置不变,当我执行

  • 我在项目中定义了一个模型类。和往常一样,它有一些私有变量和公共的获取者和设置者 假设在其他类中我使用这个模型,就像 然后person的私有变量保存值“my name”,我使用类的public getter访问变量,如 所以据我所知的人。getMark()返回私有变量名的引用,因此如果我修改局部变量“localMark”,它将影响Person类的私有变量,因此它会破坏变量的私有属性 前任: 我猜大多

  • 问题内容: 这个问题已经在这里有了答案 : 如何在没有换行符或空格的情况下进行打印? (22个答案) 3年前关闭。 我想知道在打印某些内容时如何删除其他空格。 就像我这样做时: 输出将是: 但是我想要: 有什么办法吗? 问题答案: 如果您不需要空格,请不要使用。使用字符串串联或格式化。 级联: 格式: 后者要灵活得多,请参见方法文档和“ 格式化字符串语法” 部分 。 您还将遇到较早的格式化样式:

  • 问题内容: 在安装gnuplot之前,我先设置环境变量。在安装过程中,出现了问题。 我想删除环境变量。我该如何实现? 问题答案: 是您要查找的命令。

  • 我正在监视一个实例并更改了其目标IP。现在,当我在grafana中绘制它时,有两条线(不同颜色)显示第一条线的尾部和第二条线的头部。 我的目标是删除第一行,只显示更新的第二行。 我的尝试是调整grafana中的时间框架,该框架有效,但会影响所有未更改的实例。 我的第二次尝试是删除prometheus中的时间序列,但是API没有启用,重新启动会导致prometheus系统中的一个小问题(这在监控方面