Search code examples
aws-api-gatewayportal

AWS Developer Portal - TypeError: Failed to fetch


I'm using the Developer Portal serverless application on AWS. It talks to the AWS API Gateway and allows you to send requests to a published API based on info from the GW. When I try to make calls, I get this error:

TypeError: Failed to fetch

Does anyone know where this comes from and how to troubleshoot Developer Portal?

Any suggestions welcome.


Solution

  • This process worked for me while using the serverless framework.

    To be able to access your API resources from the API developer portal, I recommend that you manually add 'Access-Control-Allow-Origin': 'https://YOUR_DEVELOPER_PORTAL_URL' to your response headers in your Lambda endpoints as shown in the code snippet below:

        'use strict';
    
        exports.handler = function(event, context) {
    
            var responseCode = 200;
    
            var response = {
                statusCode: responseCode,
                headers: {
                    "x-custom-header" : "your custom header value",
                    "Access-Control-Allow-Origin": "https://YOUR_DEVELOPER_PORTAL_URL",
                    "Access-Control-Allow-Headers": "Content-Type",
                    "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
                },
                body: JSON.stringify(event)
            };
    
            context.succeed(response);
        };
    

    You can also checkout How to CORS for more help.