如何在 lambda 中获取当前执行角色? [英] How to get the current execution role in a lambda?

查看:41
本文介绍了如何在 lambda 中获取当前执行角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 lambda 时遇到问题,它似乎无权执行某项操作,并想获取一些故障排除信息.

I'm having issues with a lambda that does not seem have the permissions to perform an action and want to get some troubleshooting information.

我可以这样做以获取当前用户:

I can do this to get the current user:

print("Current user: " + boto3.resource('iam').CurrentUser().arn)

有没有办法在运行时获取执行角色?更好的是,有没有办法动态获取附加到此角色的策略?

Is there a way to get the execution role at runtime? Better yet, is there a way to get the policies that are attached to this role dynamically?

它们不应该从我创建 lambda 时改变,但我想确认一下.

They shouldn't change from when I created the lambda, but I want to verify to be sure.

推荐答案

检查这个:list_attached_user_policies

列出附加到指定 IAM 的所有托管策略用户.

Lists all managed policies that are attached to the specified IAM user.

IAM 用户还可以嵌入内联策略​​.

An IAM user can also have inline policies embedded with it.

如果您只需要内联策略:get_user_policy

If you want just the inline policies: get_user_policy

检索嵌入在指定的 IAM 用户.

Retrieves the specified inline policy document that is embedded in the specified IAM user.

这篇关于如何在 lambda 中获取当前执行角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆