Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
Delete Function on the API Getaway

I have a partition key and a sort key on table (DynamoDB)

partition key: ClientID sort key: CaseID

The Delete Code (Lambda):

    'use strict';
const AWS = require('aws-sdk');

exports.handler = async (event, context) => {
  const documentClient = new AWS.DynamoDB.DocumentClient();

  let responseBody = "";
  let statusCode = 0;
  
  const {ClientID} = event.pathParameters;
  const {CaseID} = event.pathParameters;

  const params = {
    TableName: "Case",
    Key: {
     ClientID: ClientID,
     CaseID: CaseID
    }
  };
  
  try {
    const data = await documentClient.delete(params).promise();
    responseBody = JSON.stringify(data.Items.key);
    statusCode = 204;
  } catch(err) {
    responseBody = `Unable to delete Case: ${err}`;
    statusCode = 403;
  }

  const response = {
    statusCode: statusCode,
    headers: {
      "Content-Type": "application/json",
      "access-control-allow-origin":"*"
    },
    body: responseBody
  };

  return response;
};

If I try to delete element on API Getaway:

I got this error:

Status: 403 Unable to delete Case: ValidationException: The provided key element does not match the schema

How I can fix this error.

On The AWS Lambda with API Gateway:

I get this error:

Response "errorType": "TypeError", "errorMessage": "Cannot destructure property 'ClientID' of 'event.pathParameters' as it is undefined.",

Thank you.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The issue is in your params:

const params = {
    TableName: "Case",
    Key: {
     ClientID: ClientID,
     CaseID: CaseID
    }
  };

You have constants in your code with the same names as the Key portion of params, so it would be replaced with the constant's value. You should add quotes around your keys:

const params = {
    TableName: "Case",
    Key: {
     "ClientID": ClientID,
     "CaseID": CaseID
    }
  };

Option 2 I had a similar issue in Python, where I had to add types of data as well (basically it's DynamoDB JSON)

const params = {
    TableName: "Case",
    Key: {
     "ClientID": {"S": ClientID},
     "CaseID": {"S": CaseID}
    }
  };
about 4 years ago · Juan Pablo Isaza Relatório

0

According to the documentation (for proxy integrations) pathParameters is null, so both ClientID and CaseID will come empty and you will get an error from DynamoDB, when you try to get an item. Examine the format of the input format and modify your code accordingly.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda