amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Amplify - API - DynamoDB Delete Request - Endpoint Not Recognized

Open Smith-Steve opened this issue 10 months ago • 1 comments

Amplify CLI Version

12.10

Question

I have configured a "post" and "get" call with the library aws-amplify/api. The get call works for both the general, "get" request and the "get" request, when I reduce it down to one item.

When I attempt to use the same endpoint, and configurations, for a del - or a delete request - I'm getting a 404 error. What confuses me about this is that the same endpoint works for 'get' but doesn't work for 'del'.

I've reviewed the AWS documentation and believe that my code is the same. The Profile I'm using on my AWS CLI is good - and I can see that the REST API that was configured through the amplify CLI questionnaire does have the permission to delete specifically specified in the IAM Profile it utilizes.

I've tried reviewing a number of questions on Stackoverflow, github and elsewhere, but most of the questions utilize either GraphQL, or their about deleting Amplify or an individual service within a stack. These are both obviouisly not much help.

Below I've attached the relevant code for two of the functions. The function that works with the same endpoint, the 'get' function, and the 'delete' function - the one that doesn't work. However, the entire git repository is here if you find you need additional information in digging into this.

I've battered my head against this issue for two days. I even generated a new project, and then tried deleting the resources and re-adding them. Any help would be greatly appreciated. I'm also hoping to avoid getting voted off the island here, so I reviewed the community rules/standards but it seemed I was within rules to ask a question.

I have a hard time believing that something is wrong/buggy with the library. Please advise.

GetOneCustomer - Working

async function getOneCompany() {
  try {
    const restOperation = del({
      apiName: GladwyneAPIName,
      path: `${GladwynePath}/1`,
    });
    console.log("Get One Worked");
    const { body } = await restOperation.response;
    const response = await body.json();
    console.log("Response Recieved: ", response);
    return response;
  } catch (error) {
    console.log("Get Call Failed: ");
    console.log(error.response.body);
  }
}

Delete One Customer - Not Working

async function deleteOneCustomer(customer) {
  try {
    const returnedStatusCode = del({
      apiName: GladwyneAPIName,
      path: `/Gladwyne/Customer/${customer.CustomerId}`,
      options: {
        queryParams: {
          CustomerId: customer.CustomerId,
        },
      },
    });
    const { body } = await returnedStatusCode.response;
    const returnedResult = await body.json();
    console.log("Returned Result: ", returnedResult);
    return returnedResult;
  } catch (error) {
    if (error instanceof ApiError) {
      if (error.response) {
        const { statusCode, headers, body } = error.response;
        console.error(
          `Received ${statusCode} error response with payload: ${body}`
        );
      }
    }
    console.log("Plain old error message: ", error);
    logger.error("Error from class: ", error);
  }
}

I'm getting a response of, Unknown Error: Unknown Error and this too

DELETE https://{ID}.execute-api.us-east-1.amazonaws.com/gladwyne/Gladwyne/Customer/3?CustomerId=3 404 (Not Found)

When I turn on the advanced logging, I am also returned this object. Here it is for what it is worth..

Received 404 error response with payload: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot DELETE /Gladwyne/Customer/3</pre>
</body>
</html>

Any thoughts/advice on this matter would be appreciated.

Smith-Steve avatar Apr 11 '24 02:04 Smith-Steve

Hi @Smith-Steve ,Thank you for bringing this up. Could you please share the URL for the GET request so I can better understand the issue?

AnilMaktala avatar Apr 12 '24 12:04 AnilMaktala

Hey 👋 , This issue is being closed due to inactivity. If you are still experiencing the same problem and need further assistance, please feel free to leave a comment. This will enable us to reopen the issue and provide you with the necessary support.

AnilMaktala avatar May 28 '24 13:05 AnilMaktala

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 28 '24 13:05 github-actions[bot]