gpt4 book ai didi

amazon-web-services - AWS Lambda 是否缓存 API 响应?

转载 作者:行者123 更新时间:2023-12-04 22:03:07 24 4
gpt4 key购买 nike

我的 Lambda 函数调用 CloudWatch 描述警报 API。
然后删除这些警报。
我使用 CloudWatch Cron Event 作为触发器。

我的印象是带有警报的响应被缓存,即使它们被删除仍然会出现。

AWS Lambda 中是否有任何缓存系统?

最佳答案

缓存响应的是您的代码。不是 Lambda。

要修复它,您必须通过确保调用 API 来修复您的代码。内您的处理程序并返回它而不将其存储在处理程序函数的范围之外。

出于说明目的,

不要

const response = callAnApi()

async function handler(event, context, callback) {
// No matter how many times you call the handler,
// response will be the same
return callback(null, response)
}


async function handler(event, context, callback) {
// API is called each time you call the handler.
const response = await callAnApi()

return callback(null, response)
}

引用: AWS Lambda Execution Model

Any declarations in your Lambda function code (outside the handler code, see Programming Model) remains initialized, providing additional optimization when the function is invoked again. For example, if your Lambda function establishes a database connection, instead of reestablishing the connection, the original connection is used in subsequent invocations. We suggest adding logic in your code to check if a connection exists before creating one.

关于amazon-web-services - AWS Lambda 是否缓存 API 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47768277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com