Error when saving to Storage at Google Cloud Function: { Error: Could not refresh access token: Unsuccessful response status code...}

Viewed 371

I've written my code some month ago, and now without changing something there is an error message and I don't know why. My Code in a Google Cloud Function loads a picture from an AWS S3 bucket to google cloud and saves it in a bucket, which was actually working some month ago! My code is running node.js 8:

            const tmpdir = os.tmpdir();
            const filePath = path.join(tmpdir, fileName);
            console.log(filePath);
            console.log(data);
            await writeFile(filePath, data.Body);

            const bucketName = "test";

            console.log('test1');
            let storage;
            if(!storage){
                storage = new Storage();
            }
            await storage.bucket(bucketName).upload(filePath, {
                gzip: false,
                metadata: {
                    cacheControl: "public, max-age=31536000"
                }
            });
            console.log('test2');
            console.log(`${filePath} uploaded to ${bucketName}.`);

"test1" is printed in the logs, but "test2" not.

The error I get:

function-138m28l2agh39{ Error: Could not refresh access token: Unsuccessful response status code. Request failed with status code 500
    at Gaxios._request (/srv/node_modules/gaxios/build/src/gaxios.js:85:23)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  response: 
   { config: 
      { url: 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fiam%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control',
        headers: [Object],
        retryConfig: [Object],
        params: [Object],
        responseType: 'text',
        timeout: 0,
        paramsSerializer: [Function: paramsSerializer],
        validateStatus: [Function: validateStatus],
        method: 'GET' },
     data: 'Could not fetch URI /computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fiam%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control\n',
     headers: 
      { connection: 'close',
        'content-length': '260',
        'content-type': 'text/plain; charset=utf-8',
        date: 'Thu, 16 Jul 2020 14:25:37 GMT',
        'x-content-type-options': 'nosniff' },
     status: 500,
     statusText: 'Internal Server Error',
     request: 
      { responseURL: 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fiam%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control' } },
  config: 
   { url: 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fiam%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control',
     headers: { 'Metadata-Flavor': 'Google' },
     retryConfig: 
      { noResponseRetries: 3,
        currentRetryAttempt: 3,
        retry: 3,
        httpMethodsToRetry: [Array],
        statusCodesToRetry: [Array] },
     params: 
      { scopes: 'https://www.googleapis.com/auth/iam,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/devstorage.full_control' },
     responseType: 'text',
     timeout: 0,
     paramsSerializer: [Function: paramsSerializer],
     validateStatus: [Function: validateStatus],
     method: 'GET' },
  code: '500' }

Did somebody face a similar issue or can somebody help? :)

0 Answers
Related