重用/tmp时如何缩放Lambda? [英] How to scale Lambda when /tmp is reused?

查看:82
本文介绍了重用/tmp时如何缩放Lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个lambda函数,该函数从DynamoDB读取并在/tmp中创建一个大文件(〜500M),最后将其上传到s3.上传后,lambda将从/tmp清除文件(因为很有可能重新使用该实例)

I have a lambda function that reads from DynamoDB and creates a large file (~500M) in /tmp that finally uploaded to s3. Once uploaded the lambda clears the file from /tmp (since there is a high probability that the instance may be reused)

即使您忽略等待时间,该功能也需要大约1分钟的时间来执行.

This function takes about 1 minute to execute, even if you ignore the latencies.

在这种情况下,当我尝试再次调用该函数时,在<中; 1m,我无法控制是否有足够的空间写入/tmp.我的功能失败了.

In this scenario, when i try to invoke the function again, in < 1m, i have no control if i will have enough space to write to /tmp. My function fails.

问题: 1.在这种情况下,已知的解决方法是什么? (可能在/tmp中留出更多空间,或确保为每个新执行都提供一个干净的/tmp) 2.关于Lambda中的文件创建和管理的最佳实践是什么? 3.我可以在Lambda上附加另一个EBS或其他存储以执行吗? 4.有没有办法让文件系统像访问s3一样,以便我的函数而不是使用/tmp可以直接写入s3?

Questions: 1. What are the known work arounds in these kind of scenario? (Potentially give more space in /tmp or ensure a clean /tmp is given for each new execution) 2. What are the best practices regarding file creation and management in Lambda? 3. Can i attach another EBS or other storage to Lambda for execution ? 4. Is there a way to have file system like access to s3 so that my function instead of using /tmp can write directly to s3?

推荐答案

我怀疑两个同时运行的AWS Lambda实例将共享/tmp或任何其他本地资源,因为它们必须完全隔离地执行.您的错误应该有不同的解释.如果您是说,AWS Lambda的后续调用会重用同一实例,那么您应该自己清除/tmp.

I doubt that two concurrently running instances of AWS Lambda will share /tmp or any other local resource, since they must execute in complete isolation. Your error should have a different explanation. If you mean, that a subsequent invocation of AWS Lambda reuses the same instance, then you should simply clear /tmp on your own.

通常,如果Lambda是资源消耗大户,则最好在ECS容器工作程序中完成该工作,并使用Lambda启动ECS任务,如

In general, if your Lambda is a resource hog, you better do that work in an ECS container worker and use the Lambda for launching ECS tasks, as described here.

这篇关于重用/tmp时如何缩放Lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆