gpt4 book ai didi

amazon-web-services - AWS IAM 角色和策略是否用简单的英语表示?

转载 作者:行者123 更新时间:2023-12-03 01:44:40 26 4
gpt4 key购买 nike

我一直在使用 AWS PHP SDK,似乎获得了除 IAM 角色和权限之外的所有内容。

有人可以用最简单的术语向我解释 IAM 角色的工作原理并解释以下术语:StatementIdActionARN最重要的是Principal用简单的英语?

为了告诉你我困惑的根源,这是我最近遇到的一个问题。我正在尝试创建一个 API 网关,其中资源的方法触发 Lambda 函数。直到我复制粘贴这段代码后它才起作用:

$lambdaClient->addPermission([
'FunctionName' => 'fn name',
'StatementId' => 'ManagerInvokeAccess',
'Action' => 'lambda:InvokeFunction',
'Principal' => 'apigateway.amazonaws.com',
]);

但在其他一些线程中,有人建议使用以下内容:

const permissions = {
FunctionName: target,
StatementId: 'api-gateway-execute',
Action: 'lambda:InvokeFunction',
Principal: 'apigateway.amazonaws.com',
SourceArn: 'arn:aws:execute-api:' + nconf.get('awsRegion') + ':' + nconf.get('awsAccountId') + ':' + nconf.get('apiGatewayId') + '/*'};

为什么第一个不包含任何帐户信息,但第二个却包含?另外,还有另一个人粘贴了完全不同的东西来获得相同的工作 him 。最后一个示例中有很多键(例如“Fn::Join”),我什至不知道从哪里开始以及它的作用。

如何知道在哪里可以找到这些政策?我们是否只是从某个地方复制粘贴它们,是否有办法确定它们。如果是这样,则必须始终指定哪些键。

任何帮助将不胜感激,因为我现在完全困惑。

最佳答案

首先,欢迎来到 AWS 的世界! :-D

让我尝试通过类比来解释您对如何理解 IAM(一般情况)的疑虑。

认为有一个名为 ORG1 的组织。

ORG1 部门: HR 部门、测试部门、DEV 部门

ORG1 的员工: EMP1、EMP2、EMP3 ... EMP10

人力资源部门成员: HR1、HR2、HR3

现在我想为人力资源部门创建一个角色,以授予他们雇用/暂停员工的权限。该策略如下所示:

{
"Version": "2012-10-17", // This is version of the template. Don't change this. This is NOT a date field for your use.
"Statement": [
{
"Sid": "SOME-RANDOM-ID-WITH-NUMBER-1P1PP43EZUVRM", // This is used as ID in some cases to identify different statments
"Principal": HR-dept, // the dept who is allowed to assume this role or the one who is allowed to invoke this role
"Effect": "Allow", // has only 2 values: ALLOW/DENY. Either You want to provided the below privileges or you want to striped off these privileges.
"Action": [
"hire",
"suspend",
], // these are privileges which are granted
"Resource": "EMP1", // the entity on whom do you want to apply those actions on. In this case employee EMP1.
"Condition": {
"ArnLike": {
"AWS:SourceArn": "HR*" // You want anyone from HR-dept whose id starts with HR to be able to execute the action.ie HR1,HR2 or HR3 .
}
}
}
]
}

现在尝试从相同的角度理解下面的代码(该代码在内部创建了一个与上面类似的模板):

const permissions = {
FunctionName: target,
StatementId: 'api-gateway-execute', // This is just an ID. Dont sweat about it.
Principal: 'apigateway.amazonaws.com', //which entity group the invoker belongs to
Action: 'lambda:InvokeFunction', // The privilege you are giving to API gateway api's
SourceArn: 'arn:aws:execute-api:.. blah blah blah' // ie. the exact Id of api-gateway which all has rights to invoke lambda function
};

在AWS中ARN是资源的唯一ID。有点像公司中的 EmployeeId。这是全局唯一的。

相信我,一开始,您在 AWS 中尝试做的事情似乎很难理解,但到了某个时候,当您继续克服所面临的每个障碍时,您就会开始感到舒服。然后您将会惊叹 AWS 功能的可定制性。

关于amazon-web-services - AWS IAM 角色和策略是否用简单的英语表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com