Help with promise timeout

Hi, I have a feature that allows a user to download a pdf created by an aws lambda based on his/her email. I’m using aws-sdk node module, and fetch api to make the request to retrieve the pdf url. Sometimes the lambda takes some time to start and return the url, and this error appears in the front (but fetch api returns the url 1-2 seconds after that error):

In my backend code I have this:

import { getAwsConfig, connectWithAws } from 'backend/aws/cognitoClient';
import { apigClientFactory } from 'backend/aws/apigClient';

export async function getWorkingLetter(token, email) {
 connectWithAws(token);
 var data = await getApigClient(email);
 return callApiGateway(data, email);
}

async function getApigClient(email) {
 let config = await getAwsConfig(); //gets the credentials from aws getCredentials method that per default is void and asynchronous, so to return the url I had to create a promise and make it sync
 var apigClient = apigClientFactory.newClient({
        accessKey: config.accessKey,
        secretKey: config.secretKey,
        sessionToken: config.sessionToken,
        region: 'us-west-2'
    });
 var params = {
        para
    };
 return apigClient.proxyGet(params, {}, {});
}

function callApiGateway(data, email) {
 return fetch(url, {
 "method": data.method,
 "headers": {
 data.headers,
            }
        })
        .then((httpResponse) => httpResponse.text())
        .then((text) => {
            console.log('url from back ' + text);
 return text;
        })
        .catch(err => Promise.reject("Call to api gateway did not succeed: " + err));
}

cognitoClient.js

import AWS from 'aws-sdk';

export function connectWithAws(token) {
    AWS.config.update({ region: 'us-west-2' });
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
        IdentityPoolId: 'xxxxxxx',
        Logins: {
 'accounts.google.com': token
        }
    });
}
export async function getAwsConfig() {
 return new Promise(function (resolve, reject) {
        AWS.config.getCredentials(async function (err) {
 if (err) {
                console.log('Error getting credentials', err);
 return reject(err);
            }
            resolve({
                accessKey: AWS.config.credentials.accessKeyId,
                secretKey: AWS.config.credentials.secretAccessKey,
                sessionToken: AWS.config.credentials.sessionToken,
                region: 'us-west-2'
            });

        });
    });
}

Front end:

var url = await getWorkingLetter(token, email);
console.log('this is the url: ' + url);ç

I don’t know whats the promise that I’m missing and I’ve tried to set all promises timeout to 20 seconds but didn’t worked either. Does anyone have a clue?

Thanks!