0

我有一个在 AWS Lambda 上运行的 node.js 应用程序。Lambda 与 VPC 连接。它使用静态 IP 上网。我使用 v10.23.0 dropbox-sdk-js。它似乎总是在我的本地运行,但有时在 lambda 上运行,有时会出现获取错误。

我的代码是这样的:

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();

错误日志:

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'
}
4

1 回答 1

1

我从 lambda 中分离了 VPC,它起作用了。我认为 AWS 在您使用 VPC 时会阻止获取。

于 2022-01-25T18:18:59.513 回答