在 lambda 中使用 dynamoDB 时出现 AWS Lambda 权限错误

AWS Lambda authority error while using dynamoDB at lambda

我正在使用 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账号

i'm using root account, why authority error occurred? i want to use root account

您的功能,使用 lambda execute role,您的 IAM user/root 权限不适用于此处。您必须使用 DyndamoDB 权限更新执行角色。

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

第一步。 作用:!GetAtt DeleteAppConfigurationsLambdaRole.Arn 。详情[此处][1].

示例。

让我们通过 CFN 脚本创建一个 Dynamodb Table,并启用流。

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