Got a validation error for the tableName, but can't figure out what it is

0

Hello!

The exact error read as follows:

"code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "1 validation error detected: Value '[object Object]' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+",
          "code": "ValidationException",
          "time": "2019-07-25T05:43:18.119Z",
          "requestId": "xxx",
          "statusCode": 400,
          "retryable": false,
          "retryDelay": 42.11544763698385,
          "stacktrace": [ ...

My guess is that the problem is the name of the table but it's named accordingly. Here's the implementation:

const putItem = (tableName, newItem) =>
  new Promise((resolve, reject) => {
    const params = {
      TableName: tableName,
      Item: newItem,
    };
    docClient.put(params, (err, data) => {
      if (err) {
        return reject(err);
      }
      return resolve(newItem);
    });
  });

Since I'm using GraphQL here's the resolver:

const resolvers = {
  Mutation: {
    createUser: (root, { params }) => {
      const tableName = 'Users';
      return bcrypt
        .hash(params.password, 12)
        .then(hashedPassword => {
          const newUser = {
            _id: uuidv5(params.email, nameSpaces.usersTable),
            email: params.email,
            password: hashedPassword,
          };
          return dynamoConnection.putItem(newUser, tableName);
        })
        .then(result => ({ ...result, password: null }))
        .catch(err => {
          throw err;
        });
    },
  },
};

I'm at loss as to what to do next, tried Googling but got no really actionable results and every other find was unrelated to the same error.

What can I provide in order to debug this error?

Any help is greatly appreciated, tyvm.

Edited by: fillipvt on Jul 25, 2019 6:25 AM

已提问 5 年前7811 查看次数
3 回答
0
已接受的回答

It looks like you have switched the arguments for tableName and newUser. You passed the newUser argument first, it is being interpreted as the tableName, but since it's an Object not a string it doesn't match the regular expression for table names.

已回答 5 年前
0

Hi, you are trying to create a table named 'Users' and you are getting an error, correct?
The 'Users' is a valid table name, I was just able to create a new table with that name. I am not as familiar with the GraphQL syntax, so I tried this using Python (below), and it worked as expected. Can you describe what specifically you are trying to do, and I can help out. Thank you.

dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.create_table(
    TableName='Users',
    KeySchema=[
        {
            'AttributeName': 'pk',
            'KeyType': 'HASH'  #Partition key
        },
        {
            'AttributeName': 'sk',
            'KeyType': 'RANGE'  #Sort key
        }
    ],
    AttributeDefinitions=[
        {
            'AttributeName': 'pk',
            'AttributeType': 'N'
        },
        {
            'AttributeName': 'sk',
            'AttributeType': 'S'
        },

    ],
    ProvisionedThroughput={
        'ReadCapacityUnits': 10,
        'WriteCapacityUnits': 10
    }
)
AWS
已回答 5 年前
0

Ty Kevin, you are totally correct. Such a silly mistake...

已回答 5 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则