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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠