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年前7808ビュー
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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ