【问题标题】:User is not authorized to perform: dynamodb:CreateTable on resource:用户无权执行:dynamodb:CreateTable on resource:
【发布时间】:2020-10-31 20:32:14
【问题描述】:

当我尝试运行查询表 example_user 的 lambda 函数 register 时,它会抛出以下错误。我的代码只是试图从表 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文件中的一个sn-p

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"

【问题讨论】:

    标签: aws-lambda amazon-dynamodb serverless-framework dynamoose


    【解决方案1】:

    您应该可以使用dynamoose.model('example_user', schema, {"create": false}) 来避免创建表https://dynamoosejs.com/guide/Model/

    【讨论】:

    • 是的,我知道没有dynamodb:CreateTable,但我真的需要吗?因为我没有在我的代码中创建任何表
    • @imin 不是dynamoose 的专家,但如果表example_user 尚未创建,Dynamoose 将在您的dynamoose.model 行中创建表。 github.com/dynamoose/dynamoose/blob/master/lib/Model/…
    • 感谢您的回复 LostJon;我添加了 CreateTable,现在我得到的错误是“表已经存在”
    • @imin 太令人沮丧了......绝对是带有dynamoose 包的东西。你应该能够做到dynamoose.model('example_user', schema, {"create": false}) 来摆脱这一切dynamoosejs.com/guide/Model
    • 谢谢LostJon,我实际上去过那个页面,但我的快速阅读似乎跳过了那部分哈哈。您可以在上面发表您的评论作为答案吗?那我就接受了。
    猜你喜欢
    • 2016-04-19
    • 1970-01-01
    • 2023-03-19
    • 2014-03-24
    • 2020-06-08
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    相关资源
    最近更新 更多