There is no 'Access-Control-Allow-Origin' header found on the requested resource while utilizing AWS API Gateway in conjunction with AWS Lambda

Working on my backend, I have integrated AWS API gateway with AWS Lambda. I made sure to enable cors for my endpoint. However, upon testing the endpoint on the browser, I encountered the following error:

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Incorporating redux thunk, I structured my actions file in this manner:

import Cookies from 'universal-cookie';
import fetch from 'node-fetch';

export function fetchUsers(){

return (dispatch) => {

  const headers={
    "Content-Type":"application/json",
    "Authorization":cookies.get('idToken')
  }

  return fetch(`${url}/accounts`,{method:"GET",headers:headers }).then(response => console.log(response));
}

Investigating further, I noticed that while my OPTIONS and GET requests are returning a 200 OK response in the network options of the web browser, the current API does take approximately 11 seconds to generate a response.

I am seeking assistance with resolving these issues. Can someone provide guidance?

Answer №1

When facing troubleshooting difficulties, it's essential to consider the steps you've already taken. Here are some suggestions that might help:

  1. If CORS is enabled, don't overlook the importance of performing a "Deploy API". This step is often forgotten but crucial.
  2. To ensure proper functioning when using Lambda Proxy integration in APIGateway, make sure to include the necessary 'headers' properties in the lambda response. If the endpoint is set to use other types of integrations, manual adjustment of headers in the endpoint settings will be required.

    {
        'Access-Control-Allow-Origin': '*'
        , //you can add other optional entries here
    }
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring ways to personalize the behavior and style of the material-ui Accordion component

There is a div container in gray with an accordion component containing only one AccordionSummary component. Below that is another div in blue. The initial view looks good (see pic #1). When the accordion is expanded: The AccordionDetails component is dis ...

No testing detected, ending with code zero - NPM and YARN

After installing node js and yarn, I attempted to run an application/script developed by someone else. However, when running the test, I encountered the following message: No tests found, exiting with code 0 Watch Usage › Press f to run only failed tes ...

What is the best way to reference the className within nested SCSS when working with Next.js and React.js?

I am working on customizing a navbar that includes a hamburger button. My goal is to change the style, specifically the bar color and the appearance of the hamburger button, upon tapping. I have already attempted using &:active and .activeBar in the SCSS f ...

How can I customize the styling of Autocomplete chips in MUI ReactJS?

Trying to customize the color of the MUI Autocomplete component based on specific conditions, but struggling to find a solution. Any ideas? https://i.stack.imgur.com/50Ppk.png ...

Encountering difficulties while attempting to transition from angular 9 to angular 10

I attempted to upgrade my Angular project by running the following commands: $ ng update @angular/core@9 @angular/cli@9 $ ng update @angular/core @angular/cli However, when I executed the last command in the console, it resulted in an error message: Your ...

Attempting to create a TypeScript + React component that can accept multiple types of props, but running into the issue where only the common prop is accessible

I am looking to create a component named Foo that can accept two different sets of props: Foo({a: 'a'}) Foo({a: 'a', b: 'b', c:'c'}) The prop {a: 'a'} is mandatory. These scenarios should be considered i ...

The nextjs API route handler is experiencing an issue due to the absence of the Prisma Post request

Encountering a problem while sending a JSON content post request to Next.js API route handlers using Thunder Client. { "category_name": "Category Name" } Getting a 500 Internal Server Error when making a POST request via Thunder Clie ...

Automatic suggestions for my personalized npm module (written in ES6/Babel) in Webstorm

When I utilize the material-ui package in Webstorm, I am able to experience helpful auto-completion using the ctrl+space shortcut: https://i.stack.imgur.com/Pivuw.png I speculated that this feature may be attributed to the inclusion of an index.es.js fil ...

To utilize this specific version of npm, you must update to a more recent Node.js version. However, your current Node version surpasses v10

My command line is showing an error even though I already have a node version higher than 10.24.1. I'm unsure what the problem could be. I am utilizing nvm for managing my node versions. In an attempt to resolve the issue, I've uninstalled and ...

Is there a way to ensure that the useEffect hook only runs after the useNavigate hook has been utilized? How can I prompt the initial render to occur only following the useNavigate

After using the useNavigate hook, how can I ensure that useEffect runs and triggers an initial render in my component? Within the App.js component, which serves as the homepage with the "/" path, the following code is implemented: const [contact ...

Incorporating a personalized `PNG` image into a Material UI icon: a step-by

Incorporating material-ui@next into my React application has been smooth sailing so far. However, I've encountered a challenge while trying to utilize the Icon component with dynamically changing images in png format. Despite researching extensively o ...

Vercel deployment issue: Hidden input values not being detected as expected

Whenever I attempt to update the data on Vercel, an error message is displayed: invalid input syntax for type uuid: "undefined" - unable to save Oddly enough, the data updates successfully when done locally. This is how I submit the form: <form onSu ...

Steps for unzipping a local file with a gulp workflow

Hey everyone, I'm currently trying to figure out how to use a gulp task to extract a JAR file (which is essentially a zip file). However, I'm having trouble understanding how to connect a stream with the unzip.Extract() method. Below is the Gulp ...

In what situations should you avoid using the shrinkwrap & lock files generated by NPM?

Recent updates in NPM have made it possible for automatic generation of package-lock.json files, streamlining the process of creating reproducible builds for team developers. Previously, manual intervention was required to produce a npm-shrinkwrap.json fil ...

Issue: It seems like there is an error with using functions as a React child. Uncertain about the exact location

This specific issue is one of the two errors I have come across in the same application referenced in my previous inquiry. The first error encountered is as follows: Warning: Functions are not valid as a React child. This may occur if you mistakenly return ...

Obtaining AWS Cognito token using AWS Amplify's UI-React

I'm currently developing a Next.js frontend and NestJS backend application, and I am configuring the login component using the @aws-amplify/ui-react library. Following the steps outlined in the documentation here. import { Amplify } from 'aws-amp ...

Develop a customizable Stepper component that can respond to click events for moving forward and backward in a

Looking to create a Stepper with the ability to handleNext and handleBack directly from the StepLabel using onClick events. Struggling to figure it out. Here is the sandbox link for reference: https://codesandbox.io/s/stepper-forked-2q1wd export default f ...

Mastering the correct method for passing $NODE_DEBUG_OPTION to npm-run-all in IntelliJ IDEA

Running on my system with Ubuntu 16.04, I have IntelliJ IDEA Ultimate 2017.2, node v6.11.2, and npm v3.10.10. I am trying to debug a node.js application that has the following package.json start entry: "start:" "npm-run-all --parallel serve-static open-st ...

Experiencing Problems with Routing React page on Apache2 Server

I'm encountering difficulties accessing routes other than the homepage on my React website, which is currently hosted on an Apache2 web server. You can find the page here: www.TJBrackett.com After attempting to add a .htaccess file to the directory ...

Exploring NextJS: Implementing Routing for Multilingual Support

I am currently working on developing a multilanguage website using Next JS. For the translation functionality, I have integrated the next-translate package into my project. When it comes to generating posts, I have opted for static generation as my appro ...