【问题标题】:AWS Lambda authority error while using dynamoDB at lambda在 lambda 上使用 dynamoDB 时出现 AWS Lambda 权限错误
【发布时间】:2021-07-18 19:42:58
【问题描述】:

我使用 AWS Lambda 作为根账户。但是当我尝试在 lambda 中添加 dynamo-db 作为触发器时,AWS 说发生了一些权限错误。

Please ensure the role can perform the GetRecords, GetShardIterator, DescribeStream, ListShards, and ListStreams Actions on your stream in IAM. 

我使用的是root账号,为什么会出现权限错误? 我要使用root帐号

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-dynamodb


    【解决方案1】:

    我使用的是root账号,为什么会出现权限错误?我想用root帐号

    您的函数使用 lambda execute role,您的 IAM 用户/根权限不适用于此处。您必须使用 DynamoDB 权限更新执行角色。

    【讨论】:

      【解决方案2】:

      Lambda 函数使用执行角色来访问 AWS 服务和资源,这可以在 lambda 创建向导或云形成脚本中设置

      第 1 步。 角色: !GetAtt DeleteAppConfigurationsLambdaRole.Arn 。详情[这里][1]。

      例子。

      让我们通过启用流的 CFN 脚本创建如下所示的 Dynamodb 表。

      DynamoDBTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
         AttributeDefinitions:
          -
            AttributeName: "id"
            AttributeType: "S"
         KeySchema:
          -
            AttributeName: "id"
            KeyType: "HASH"
         TableName: DynamoDBTable
      
         SSESpecification:
            SSEEnabled: true
      
         StreamSpecification:
            StreamViewType: "NEW_AND_OLD_IMAGES"
      

      然后创建一个可以访问流的 lambda 执行角色,如下所示,

      DynamoDBStreamLambdaRole:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Statement:
          - Action:
            - sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
              - lambda.amazonaws.com
          Version: '2012-10-17'
        Path: /
        RoleName:  "IAM-ROLE-DynamoDBStreamLambdaRole"
        Policies:
        - PolicyDocument:
            Statement:
            - Action:
              - dynamodb:DescribeStream
              - dynamodb:GetRecords
              - dynamodb:GetShardIterator
              - dynamodb:ListStreams
              Effect: Allow
              Resource: !GetAtt DynamoDBTable.StreamArn
      
            Version: '2012-10-17'
          PolicyName: "IAM-POLICY-DynamoDBStreamLambdaStreamaccess"
        ManagedPolicyArns:
          - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
      

      然后您可以按照步骤 1 中的说明将此角色附加到 lambda。 [1]:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-role

      【讨论】:

      • 您认为 OP 使用 Cloudformation 的原因是什么?
      猜你喜欢
      • 1970-01-01
      • 2023-02-20
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 2021-07-25
      相关资源
      最近更新 更多