【问题标题】:Dropbox API integration on AWS Lambda gets FetchError (ETIMEDOUT)AWS Lambda 上的 Dropbox API 集成获取 FetchError (ETIMEDOUT)
【发布时间】:2022-01-26 02:18:59
【问题描述】:

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

我的代码是这样的:

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

【问题讨论】:

标签: node.js aws-lambda amazon-vpc dropbox-sdk-js aws-nat-gateway


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-04-19
    • 2017-04-18
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 2017-02-08
    • 2019-06-04
    • 2018-12-25
    • 2020-10-05
    相关资源
    最近更新 更多