使用实例配置文件时如何在 AWS CLI 中设置配置文件名称

How to set profile name in AWS CLI when using instance profile

我创建了一个关联了实例配置文件的实例。 我正在尝试 运行 在实例上加壳而不使用访问和密钥,因此我使用 profile 选项。

但是,打包程序需要配置文件名称,但实例配置文件不会创建配置文件名称,也不会在 ~/.aws 下创建凭据。

我可以看到通过 AWS CLI 关联的访问密钥和秘密密钥,但是它没有配置文件名称。

[ec2-user@ip-172-31-19-132 ~]$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************3IO2         iam-role
secret_key     ****************cFvD         iam-role
    region           ap-southeast-2             imds

据我了解 ,访问密钥和密钥经常轮换,我想知道如何将配置文件名称永久设置为凭据,以便我可以在打包程序中引用它。

不会有配置文件名称,因为您使用的是 IAM 角色。相反,您应该 natively use the IAM role

Finally, Packer will use credentials provided by the task's or instance's IAM role, if it has one.

This is a preferred approach over any other when running in EC2 as you can avoid hard coding credentials. Instead these are leased on-the-fly by Packer, which reduces the chance of leakage.

删除对配置文件选项的引用,它应该像 SDK/CLI 功能一样在本机工作。