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

gefragt vor 5 Jahren7807 Aufrufe
3 Antworten
0
Akzeptierte Antwort

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.

beantwortet vor 5 Jahren
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
beantwortet vor 5 Jahren
0

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

beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen