简体   繁体   English

在 Aws lambda 和 EC2 实例之间共享文件

[英]Share Files between Aws lambda and EC2 instance

I want a solution to share files between AWS Lambda and EC2 (Windows) .我想要一个在 AWS Lambda 和 EC2 (Windows)之间共享文件的解决方案。

How can lambda place the file inside the ec2 file system after it notifies by the s3event?在 s3event 通知之后,lambda 如何将文件放入 ec2 文件系统? In the same way, if way lambda wants to access the ec2 file system that also should be possible.同样,如果 lambda 想要访问 ec2 文件系统,那也应该是可能的。

For example: if any file created in s3 will trigger notify lambda, then that would be copied to EC2 drive in some path, then application inside server will process it and so on.例如:如果在 s3 中创建的任何文件将触发通知 lambda,则该文件将被复制到某个路径中的 EC2 驱动器,然后服务器内部的应用程序将对其进行处理等等。

Please let me know any possible way to achieve this.请让我知道实现这一目标的任何可能方法。 Thanks in advance.提前致谢。

You can have your S3 send a notification event when an object is created.您可以让 S3 在创建对象时发送通知事件。

In your lambda function set up a S3 trigger that consumes s3 notification events - checkout this tutorial: Using an Amazon S3 trigger to invoke a Lambda function在您的 lambda 函数中设置一个使用 s3 通知事件的 S3 触发器 - 查看本教程: 使用 Amazon S3 触发器调用 Lambda 函数

Then you probably would want your lambda to call an endpoint on your EC2 service to trigger the copy function, or source the event in a message broker like SQS if you care about real-time processing.然后,如果您关心实时处理,您可能希望 lambda 调用 EC2 服务上的端点以触发复制功能,或者在消息代理(如 SQS)中获取事件源。

Use EFS .使用EFS This is a network file system which can be simultaneously mounted on EC2 instance as well as within Lambda functions.这是一个网络文件系统,可以同时挂载在 EC2 实例和 Lambda 函数中。

As the process is quite lengthy, and the question didn't mention which OS is being used (EFS is not supported on Windows), or what Lambda runtime is desirable.由于这个过程相当漫长,而且问题没有提到正在使用哪个操作系统(Windows 不支持 EFS),或者什么 Lambda 运行时是可取的。 Its impractical to document a full example, however there are some useful guides to get started.记录一个完整的例子是不切实际的,但是有一些有用的入门指南。

There is a blog on using EFS within Lambda functions.有一篇关于在 Lambda函数中使用EFS的博客。 The Lambda function would need access to read the object from the S3 bucket and store it on the EFS volume. Lambda 函数需要访问权限才能从 S3 存储桶读取对象并将其存储在 EFS 卷上。

An example of mounting EFS on an EC2 instance running Amazon Linux also exists.还有一个运行 Amazon Linux的 EC2实例上挂载 EFS的示例。

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

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