Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Incremento del valor de DynamoDB con AWS SDK v3

Estoy intentando migrar mis Lambdas v2 a v3 y tengo algunos problemas para incrementar un valor. Aquí está mi método v2:

 const params = { TableName: process.env.USER_TABLE_NAME!, Key: { UID }, UpdateExpression: 'SET #numRatings = #numRatings + :increment', ExpressionAttributeNames: { '#numRatings': 'numRatings' }, ExpressionAttributeValues: { ':increment': 1 }, ReturnValues: 'ALL_NEW' }; return await DB.update(params).promise();

método v3:

 const params = { TableName: process.env.USER_TABLE_NAME!, Key: { UID }, UpdateExpression: 'set numRatings = numRatings + :increment', ExpressionAttributeValues: { ':increment': 1 }, ReturnValues: 'ALL_NEW' } as unknown as UpdateItemCommandInput; try { const response = await dbClient.send(new UpdateItemCommand(params)); console.log('response', response); } catch (error) { console.error('error', error); }

Estoy usando TypeScript y VS Code da este error:

 Types of property 'Key' are incompatible. Type '{ UID: string; }' is not comparable to type '{ [key: string]: AttributeValue; }'. Property 'UID' is incompatible with index signature. Type 'string' is not comparable to type 'AttributeValue'

CloudWatch da este error inútil:

No se puede leer la propiedad '0' de indefinido

Estoy realmente confundido ya que, por lo que puedo decir, he seguido la documentación correctamente, su equivalente de "parámetros" se define así:

 export const params = { TableName: "TABLE_NAME", Key: { primaryKey: "VALUE_1", // For example, 'Season': 2. sortKey: "VALUE_2", // For example, 'Episode': 1; (only required if table has sort key). }, // Define expressions for the new or updated attributes UpdateExpression: "set ATTRIBUTE_NAME_1 = :t, ATTRIBUTE_NAME_2 = :s", // For example, "'set Title = :t, Subtitle = :s'" ExpressionAttributeValues: { ":t": "NEW_ATTRIBUTE_VALUE_1", // For example ':t' : 'NEW_TITLE' ":s": "NEW_ATTRIBUTE_VALUE_2", // For example ':s' : 'NEW_SUBTITLE' }, ReturnValues: "ALL_NEW" };

Mis disculpas si son demasiados ejemplos de código, pero quería ser exhaustivo. UID es una cadena. Gracias de antemano por cualquier ayuda

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Las claves y ExpressionAttributeValues necesitan su tipo de Dynamo definido de la siguiente manera:

 ... Key: { UID: { S: UID } }, ... ExpressionAttributeValues: { ':val': { N: '1' } },
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!