简体   繁体   English

在 AWS Lambda 中加载 static 文件的最佳方式

[英]Best way to load static files inside AWS Lambda

Im writing a serverless applications(aws lambdba and sam) to do some data transformation wherein I pass a list of jsons to my api and it updates the keys based on my mapping file which can lie inside s3 and returns the update list of jsons我正在编写一个无服务器应用程序(aws lambdba 和 sam)来进行一些数据转换,其中我将一个 json 列表传递给我的 api 并根据我的映射文件更新密钥,该文件可以位于 s3 中并返回 json 的更新列表

What is the best way to load a mapping file within lamda?在 lamda 中加载映射文件的最佳方式是什么? coz the file read happens everytime my lambda func is called.因为每次调用我的 lambda 函数时都会读取文件。 I dont want to hit a million times to get the same info, is there a way I can cache the info where I only reload the file only if I want to我不想点击一百万次来获得相同的信息,有没有一种方法可以缓存信息,我只在需要时才重新加载文件

There are multiple way to do that.有多种方法可以做到这一点。 You can download the file and store it inside the /tmp folder.您可以下载该文件并将其存储在/tmp文件夹中。 That way, you can check whether the file exists otherwise, download it from S3.这样,您可以检查文件是否存在,否则,从 S3 下载。 This folder is shared across the same lambda execution environment.此文件夹在相同的 lambda 执行环境中共享。

The other possibility, is to have the json content stored as part of lambda environment variables (4KB max) or as part of Parameter store in SSM (4KB limit as well).另一种可能性是将 json 内容作为 lambda 环境变量(最大 4KB)的一部分或作为 SSM 中参数存储的一部分(也有 4KB 限制)存储。

Finally, you can also attach EFS storage to lambda. That can be shared across different lambda execution.最后,您还可以将 EFS 存储附加到 lambda。这可以在不同的 lambda 执行之间共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM