简体   繁体   English

在Lambda Python函数中循环访问AWS账户

[英]Loop through AWS Accounts in Lambda Python Function

I have a python script that loops through all of the AWS accounts we have and lists the EC2 instances in each one. 我有一个Python脚本,该脚本循环遍历我们拥有的所有AWS账户,并在每个账户中列出EC2实例。

I want to turn it into an AWS Lambda function. 我想将其转换为AWS Lambda函数。 But I can't figure out how to pull the AWS credentials that would allow me to list the servers in all the accounts. 但是我不知道如何提取允许我在所有账户中列出服务器的AWS凭证。

How can I achieve this in AWS Lambda? 如何在AWS Lambda中实现这一目标?

  1. Create a role with cross account permissions for ec2:ListInstances 为ec2:ListInstances创建具有交叉帐户权限的角色
  2. Attach the role to the lambda function 将角色附加到lambda函数

When you create lambda you have so specify a role In IAM you can attach required permission to a lambda role. 创建lambda时,您必须指定角色。在IAM中,您可以将必需的权限附加到lambda角色。

If you want to use some specific set of credentials in a file, you can utilize AWS Systems Manager to retrieve credentials. 如果您要在文件中使用一组特定的凭证,则可以利用AWS Systems Manager检索凭证。 Though, I would recommend role on lambda 不过,我建议在lambda上使用角色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM