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

demandé il y a 5 ans7808 vues
3 réponses
0
Réponse acceptée

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.

répondu il y a 5 ans
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
répondu il y a 5 ans
0

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

répondu il y a 5 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions