部署lambda函数时AccessDeniedException

问题描述 投票:0回答:1

我试图通过AWS命令在aws中创建lambda函数。当我执行命令时,得到以下错误。但是我在AWS命令中提到的角色有足够的权限来部署lambda函数。即使角色有权限,我也不确定出了什么问题。

命令:

aws lambda create-function --function-name ukmon-appd-disabled- 
health-rules --runtime python3.7 --zip-file 
fileb://bin/disabled_health_rules.zip --handler index.handler --timeout 10 - 
-memory-size 1024 --role arn:aws:iam::99999999999:role/crossaccount

政策:

"AllowLambdaFunctionStack": {
      "Type": "AWS::IAM::ManagedPolicy",
      "Properties": {
        "Description": "Policy for allowing jenkins cross account service role to create, update, delete lambda functions.",
        "Path": "/",
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Action": [
                "lambda:InvokeFunction",
                "lambda:CreateFunction",
                "lambda:DeleteFunction",
                "lambda:GetFunction",
                "lambda:ListFunctions",
                "lambda:UpdateFunctionCode",
                "lambda:GetFunctionConfiguration",
                "lambda:UpdateFunctionConfiguration",
                "lambda:AddPermission",
                "lambda:RemovePermission",
                "lambda:CreateAlias",
                "lambda:DeleteAlias",
                "lambda:GetAlias",
                "lambda:ListAliases",
                "lambda:UpdateAlias",
                "lambda:GetPolicy",
                "lambda:InvokeAsync",
                "lambda:ListVersionsByFunction",
                "lambda:PublishVersion",
                "lambda:CreateEventSourceMapping",
                "lambda:GetEventSourceMapping",
                "lambda:ListEventSourceMappings",
                "lambda:DeleteEventSourceMapping",
                "lambda:UpdateEventSourceMapping",
                "lambda:TagResource",
                "lambda:ListTags",
                "lambda:UntagResource"
              ],
              "Effect": "Allow",
              "Resource": "arn:aws:lambda:eu-west-1:999999999999:function:crossaccount-*",
              "Sid": "AllowLambdaFuctionsStacks"
            }
          ]
        },

错误:

调用CreateFunction操作时发生错误(AccessDeniedException):User:arn:aws:sts :: 999999999999:assume-role / crossaccount / i-0d2dd689c2784f174无权执行:lambda:CreateFunction on resource:arn:aws:lambda:欧盟 - 西1:999999999999:功能:ukmon-APPD禁用健康规则

提前致谢。

amazon-web-services aws-lambda
1个回答
2
投票

我认为你在你的问题中混淆了IAM角色。您传递给create-function AWS CLI调用的IAM角色是Lambda服务在运行时将承担的角色:即您在运行时为lambda函数提供的权限。 要获得授权进行aws lambda create-function CLI调用,您的环境必须具有CreateFunction授权。

但是,如果您没有混淆角色,则您的政策中存在问题。它授权所有列出的符合Lambda资源的API调用

"Resource": "arn:aws:lambda:eu-west-1:999999999999:function:crossaccount-*",

您尝试创建的lambda函数名为ukmon-appd-disabled- health-rules只有以crossaccount-开头的函数名才会被授权。

© www.soinside.com 2019 - 2024. All rights reserved.