如何在上传开始和上传完成时收到通知?

huangapple go评论81阅读模式
英文:

How to get notification when upload has started and when it has finished

问题

我需要知道是否有一种方法可以在AWS S3开始上传时收到通知。

目前,我已经设置了AWS Lambda,当PUT操作完成时通知我的后端,但我无法知道它是否已经开始(如果它已经开始)。这是必需的,因为我的goroutine等待上传完成,但我无法知道它何时开始,我可以在goroutine上设置超时,但对于大文件和客户端的慢速互联网连接来说可能会很棘手,因为实际上客户端可能仍在上传文件。

英文:

I need to know if there's a way to get a notification from AWS S3 when the upload has started.

As of now I've set up aws lambda which notifies my backend when the PUT operation is finished, but I have no way to know when it has started (if it has started at all). This is required because my goroutine waits for the upload to be finished but I have no way to know when it has started, I could put a timeout on the goroutine but it would be tricky for large files and slow internet connections of clients because my backend would consider the operation failed when in reality the client might still be uploading the file.

答案1

得分: 1

您可以通过在AWS CloudWatch中创建一个规则来为S3指定Simple Storage Service (S3)作为服务名称,Object Level Operations作为事件类型,PutObject作为具体操作,并在创建了S3的PutObject操作的AWS CloudTrail之后,通过指定您所需的目标(例如AWS Lambda函数或AWS SNS主题)来记录AWS S3存储桶上对象上传的开始时间。

只要执行PutObject API操作(有人上传对象),如果已经创建了跟踪,则会在AWS CloudTrail中记录下来。

注意:如果需要,您还可以使用CreateMultipartUpload或UploadPart作为具体操作。

英文:

You can create an AWS CloudWatch rule for S3 by specifying Simple Storage Service (S3) as Service Name, Object Level Operations as Event Type, PutObject as Specific operation(s) and <your-bucket-name> as Specific bucket(s) by name after creating a trail in AWS CloudTrail for S3's PutObject operation and specifying your desired target, for example, AWS Lambda function or AWS SNS topic to record the start time of an object upload on AWS S3 bucket.

As soon as the PutObject API operation (someone uploads an object) will be performed, it will be recorded in AWS CloudTrail if the trail is created already.

Note: You can also use CreateMultipartUpload or UploadPart as Specific operation(s) if required.

huangapple
  • 本文由 发表于 2019年7月23日 20:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/57164484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定