0

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

{"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"
4

1 回答 1

1

您应该能够dynamoose.model('example_user', schema, {"create": false})摆脱创建表的需要https://dynamoosejs.com/guide/Model/

于 2020-10-30T12:16:15.390 回答