Amazon web services 从EC2实例访问AWS secrets manager时出现权限错误

Amazon web services 从EC2实例访问AWS secrets manager时出现权限错误,amazon-web-services,aws-secrets-manager,Amazon Web Services,Aws Secrets Manager,我有一个运行在linux EC2实例上的Python程序,我试图从secrets manager中获取一个值,但我一直得到一个权限错误 An error occurred (AccessDeniedException) when calling the GetSecretValue operation: User: arn:aws:sts::user_id_here:assumed-role/AmazonSSMRoleForInstancesQuickSetup/somestring is no

我有一个运行在linux EC2实例上的Python程序,我试图从secrets manager中获取一个值,但我一直得到一个权限错误

An error occurred (AccessDeniedException) when calling the GetSecretValue operation: User: arn:aws:sts::user_id_here:assumed-role/AmazonSSMRoleForInstancesQuickSetup/somestring is not authorized to perform: secretsmanager:GetSecretValue on resource: arn:aws:secretsmanager:eu-west-2:xxx_my_secret
在“我的IAM设置”中,用户位于具有管理员访问权限的组内,然后用户本身拥有权限
secretsmanagerradwrite


我需要更改哪些权限?

访问EC2的用户的角色与机器本身不同

计算机对机密管理器的角色和访问权限由

  • 用户角色(在AWS控制台中创建EC2时),或
  • ./aws/凭证和。/aws/配置
在我的代码中,我使用boto.utils.get\u instance\u identity()来获取区域。然后从bot3.Session()获取访问密钥和机密密钥。获取凭据()。获取冻结的凭据()


您可能还想使用botocore.credentials.RefreshableCredentials,因为get\u freezed\u credentials()中的令牌过期。

您所说的“用户”是什么意思?脚本似乎使用了分配给EC2实例的IAM角色,而不是IAM用户。如果你想使用IAM用户凭据,你应该运行
aws configure
并在本地存储凭据。你有权访问加密该机密的KMS密钥吗?所谓用户,我指的是错误代码中引用的用户,这里我对错误角色应用了权限,我在AWS控制台中找到了我的EC2实例,并从此处向其角色添加了权限