S3 对象创建触发事件到 lambda
我已经从 S3 创建了一个 AWS lambda 触发器 - 创建对象通知。当 lambda 收到对象创建通知时,它还会启动 ec2 实例。对于下一步,我希望 ec2 访问 s3 中的对象/数据并对这些数据进行一些处理。我如何从 ec2 访问该数据?
I have created an AWS lambda trigger from S3 - create object notification. When lambda gets object creation notification it also launches the ec2 instance. For the next step, I want ec2 to access the object/data form s3 and do some processing on that data. How can I access that data from ec2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 Lambda 函数启动 EC2 实例时,我希望它传递 S3 对象密钥作为 EC2 用户数据。
When the Lambda function launches the EC2 instance, I would have it pass the S3 object key as part of the EC2 user-data.
您似乎想要使用现有的 Amazon EC2 实例来处理上传到 Amazon S3 存储桶的对象。
执行此操作的标准方法是:
WaitTimeSeconds=20
减少调用次数,如果消息可用,它将立即返回)如果对象上传之间的时间间隔很长并且您希望省钱,您可以在代码中添加一些逻辑来执行 >在给定时间段内未收到消息时关闭实例。然后,您可以根据队列大小创建一个 Amazon CloudWatch 警报,该警报可以触发 AWS Lambda 函数来启动实例(如果实例当前未运行)。
要在每次 Amazon EC2 实例启动时运行脚本,您可以将其放置在
/var/lib/cloud/scripts/per-boot/
中。另请参阅:自动停止 EC2 实例当他们完成任务时 - DEV 社区
It appears that you are wanting to use an existing Amazon EC2 instance to process objects that are uploaded to an Amazon S3 bucket.
The standard method for doing this is:
WaitTimeSeconds=20
to reduce the number of calls, it will return immediately if a message is available)If there are long time-periods between object uploads and you wish to save money, you could add some logic to your code that does a Shutdown of the instance when no messages have been received for a given period of time. You could then create an Amazon CloudWatch alarm based on queue size that can trigger an AWS Lambda function to Start the instance if it is not currently Running.
To run a script every time that an Amazon EC2 instance starts, you can place it in
/var/lib/cloud/scripts/per-boot/
.See also: Auto-Stop EC2 instances when they finish a task - DEV Community