0

I have a node.js app which runs on AWS Lambda. The Lambda is connected with a VPC. It goes internet with a static IP. I use v10.23.0 dropbox-sdk-js. It always seems to run on my local but it sometimes runs on the lambda, sometimes gets fetch error.

My code is like this:

async function main() {
    const Dropbox = require('dropbox').Dropbox;
    const dropbox = {
        dbx: new Dropbox({
            accessToken: process.env.ACCESS_TOKEN,
            pathRoot: JSON.stringify({ '.tag': 'namespace_id', 'namespace_id': process.env.NAMESPACE_ID })
        })
    };
    const payload = {
        path: '',
        recursive: true,
        include_media_info: false,
        include_deleted: false,
        include_has_explicit_shared_members: true,
        include_mounted_folders: true,
        include_non_downloadable_files: true
    };

    let hasMore = true;
    let entries = [];
    let response;
    let cursor;

    while (hasMore) {
        try {
            if (cursor) {
                response = await dropbox.dbx.filesListFolderContinue({ cursor: cursor });
            }
            else {
                response = await dropbox.dbx.filesListFolderGetLatestCursor(payload);

                response = await dropbox.dbx.filesListFolderContinue({ cursor: response.result.cursor });

            }

            console.info('Entries: ', JSON.stringify(response.result.entries));

            cursor = response.result.cursor;
            entries = entries.concat(response.result.entries);
            hasMore = response.result.has_more;
        }
        catch (error) {
            console.info(error);
            return error;
        }
    }
}

main();

Error log:

2022-01-20T08:22:18.579Z    67caa239-e75c-46ce-be4c-0fcf6c154694    INFO    FetchError: request to https://api.dropboxapi.com/2/files/list_folder/continue failed, reason: connect ETIMEDOUT 162.125.4.19:443
    at ClientRequest.<anonymous> (/var/task/node_modules/dropbox/node_modules/node-fetch/lib/index.js:1483:11)
    at ClientRequest.emit (events.js:400:28)
    at TLSSocket.socketErrorListener (_http_client.js:475:9)
    at TLSSocket.emit (events.js:400:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT'
}
rdvnkrtl
  • 11
  • 2
  • Did you give the Lambda internet access as described in https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/?nc1=h_ls – st.huber Jan 24 '22 at 15:26
  • I deattached VPNC from lambda and it worked. I think AWS blocks fetching while you are using VPC. – rdvnkrtl Jan 25 '22 at 18:18

1 Answers1

1

I deattached VPC from lambda and it worked. I think AWS blocks fetching while you are using VPC.

rdvnkrtl
  • 11
  • 2