AWS Lambda - 请求的资源上不存在 'Access-Control-Allow-Origin' header

AWS Lambda - No 'Access-Control-Allow-Origin' header is present on the requested resource

我有 AWS lambda 函数,我正尝试使用 Axios 从我的 Web 应用程序调用它。它不断给出错误:“http://localhost:3000”已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' header。

我正在使用无服务器,并且已将 cors:true 属性添加到我的函数中。我还添加了:

            const response = {
                statusCode:200,
                headers: {
                    'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Credentials': true
                },
                body: JSON.stringify({
                    message: 'Ticket received',
                    TableData: data,
                }),
            };
            callback(null, response);

我仍然无法解决这个问题。非常感谢任何帮助。

我返回了 2 个不同的响应,一个是上面的响应,另一个是错误响应。一旦我将错误消息定义为 headers,它就可以正常工作了。