node.js - 使用本地调用的 lambda 函数向外部 API 发出请求并将数据记录到控制台
问题描述
我想在 Lambda 函数的帮助下使用新发布的 API 访问 Notion 数据库。
应用程序.js
/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
* @param {Object} event - API Gateway Lambda Proxy Input Format
*
* Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
* @param {Object} context
*
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
* @returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
require('dotenv').config()
const { Client } = require('@notionhq/client');
const notion = new Client({
auth: process.env.NOTION_TOKEN,
})
const getBDays = async () => {
const payload = {
path: `databases/${process.env.NOTION_DB_ID}/query`,
method: 'POST'
}
const { results } = await notion.request(payload)
console.log("DATA", results)
}
exports.lambdaHandler = async (event, context) => {
try {
getBDays()
} catch (err) {
console.log(err);
return err;
}
};
当我使用 SAM CLI 在本地调用此函数时,我看不到预期的输出。这是我在控制台中看到的
Invoking app.lambdaHandler (nodejs14.x)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs14.x:rapid-1.23.0.
Mounting /Volumes/MacOS/Projects/Projects/4. Remembery/remembery/hello-world as /var/task:ro,delegated inside runtime container
START RequestId: 423f4ea6-aeae-4780-bb36-af32db051f2b Version: $LATEST
END RequestId: 423f4ea6-aeae-4780-bb36-af32db051f2b
REPORT RequestId: 423f4ea6-aeae-4780-bb36-af32db051f2b Init Duration: 0.20 ms Duration: 1179.88 ms Billed Duration: 1200 ms Memory Size: 128 MB Max Memory Used: 128 MB
我无法弄清楚这里发生了什么。
解决方案
推荐阅读
- python - Django:每次我开发我的 django 应用程序时都必须打开虚拟环境吗
- python - Python & Selenium:遍历 WebElements 错误列表:StaleElementReferenceException
- python - 根据列表中的值过滤 pyspark 数据框
- java - Tess4J:结果字符串无法解析为 int
- .net-core - .NET Web API 从控制器名称中剥离斜杠 - 如何禁用该行为?
- python - jinja2.exceptions.UndefinedError:没有称为“脚本”的父块
- android - 如何在 webview 中有效地显示没有网络
- spring - 如果用户未在 Spring Security 中进行身份验证,如何将用户扔到 /login 以外的页面
- jsf - 在 IntelliJ 上的 Facelets 文件中调试表达式语言 (EL)
- node.js - 推荐杀死 VS Code Extension 的子进程的方法