用户无权执行:dynamodb:CreateTable 资源:

User is not authorized to perform: dynamodb:CreateTable on resource:

当我尝试 运行 我的 lambda 函数 register 查询 table example_user 时,它会抛出以下错误。我的代码只是试图从 table example_user 获取数据,而不是创建任何 table.

{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"AccessDeniedException: User: arn:aws:sts::577777777777:assumed-role/example-user-api-dev-ap-southeast-1-lambdaRole/example-user-api-dev-register is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:ap-southeast-1:577777777777:table/example_user","reason":{"errorType":"AccessDeniedException","errorMessage":"User: arn:aws:sts::577777777777:assumed-role/example-user-api-dev-ap-southeast-1-lambdaRole/example-user-api-dev-register is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:ap-southeast-1:577777777777:table/example_user"

13 UserController with email

之后抛出错误

这是我的代码:

User.js

const schema = new dynamoose.Schema({
    "email": String,
    "uid": String,
    "name": String,
    "gender": {
        "type": Number,
        "default": 0
    },
    "profileImageType": {
        "type": Number,
        "default": 0
    },
    "profileImage": String,
    "accountType": Number,
}, {
    "saveUnknown": true,
    "timestamps": true
});

module.exports = dynamoose.model('example_user', schema);

UserController.js

const User = require("./User.js");
exports.getProfile = async function(email,res){
  console.log("13 UserController with email " + email)
  var profile = await User.get(email)
  console.log("15 profile")
  console.log(profile)
  if (profile){
    return profile;
  }else{
    return false;
  }
};

下面是我的 serverless.yml 文件中的一个片段

iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:*"
      Resource: 
        - "arn:aws:s3:::profiles.example.app/*"
    - Effect: "Allow"
      Action:
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: 
        - "arn:aws:dynamodb:ap-southeast-1:577777777777:table/example_user"

您应该可以 dynamoose.model('example_user', schema, {"create": false}) 来摆脱创建 table https://dynamoosejs.com/guide/Model/

的需要