'AWS Amplify App API - API api_name does not exist

Introduction

Hi, I'm trying to setup a React App on Amplify with a serverless backend. I deployed my backend manually as a Lambda function using a docker container, and created an endpoint through API Gateway.

When I directly click on the link on API Gateway, the backend works correctly, but when i call it from the React App using API.get( . . . ), it throws an error saying API [API-NAME] does not exist.

Configuration

I have aws-amplify installed (I didn't initialize it through the CLI, I did it from the AWS Console linking the Amplify App to my GitHub Repo), and the file where I configured Amplify is the following:

amplify.ts

import Amplify, { API } from 'aws-amplify'

const awsConfig = {
  API: {
    endpoints: [
      {
        name: 'NAME-OF-API-GATEWAY-RESOURCE',
        endpoint:
          'https://1234567890.execute-api.us-east-1.amazonaws.com/default',
      },
    ],
  },
}

Amplify.configure(awsConfig)

Then, I import API in my service file and invoke it:

usersService.ts

import { API } from 'aws-amplify'

const apiName = 'astrum-backend-lambda-func-API'
const path = '/users'

const createNewUser = async (user) => {
  const myInit = {
    body: user,
  }

  const response = await API.post(apiName, path, myInit)

  return response.data
}

aws-amplify version is 4.3.14.

What I tried

  1. Changing endpoint name to the Lambda Function Name
  2. Changing the endpoint address to the exact address that works when I type it directly in a browser
  3. Smashing my head against the wall, in every direction possible

But React still throws Error

Hope someone is able to help me, thanks in advance :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source