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

标签 amazon-web-services caching aws-lambda

我的 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/

相关文章:

amazon-web-services - 如何正确配置我的 S3 存储桶以供 Transloadit 使用?

amazon-web-services - AWS S3存储桶不一致

ssl - 2 向 SSL - 将客户端证书验证与 SSL 终止分离

performance - 如何比较没有缓存的 neo4j 查询的性能?

php - 立即加载 URL 导航

python - 如何在 AWS Lambda 函数中降级 boto3 版本

amazon-web-services - 如何为 AWS CodeBuild/Code Pipeline 启用 VPC 访问?

PHP缓存机制

amazon-web-services - 在 Serverless 框架中创建 lambda 后可以创建资源吗?

node.js - 无服务器框架无法识别 tsconfig 的路径