简体   繁体   English

使用 AWS lambda [CDK] 访问 S3 中的对象

[英]Access objects in S3 using AWS lambda [CDK]

My use case is to trigger a AWS lambda daily, this can be triggered through cloudwatch, every time lambda gets triggered I have to access particular location(prefix) in S3.我的用例是每天触发 AWS lambda,这可以通过 cloudwatch 触发,每次触发 lambda 时,我都必须访问 S3 中的特定位置(前缀)。

This location contains many files and I have to process these files separately.此位置包含许多文件,我必须分别处理这些文件。 Is this Possible through AWS-CDK?这可以通过 AWS-CDK 实现吗?

I tried to check online but I couldn't find any solution to my usecase我试图在线检查,但找不到任何解决方案来解决我的用例

PS: Lambda shouldn't be triggered by S3 PS:Lambda 不应由 S3 触发

You can create 2 lambdas with read access of S3 bucket.您可以创建 2 个具有 S3 存储桶读取权限的 lambda。

Lambda1: will be triggered by CloudWatch/EventBridge event daily. Lambda1:每天都会被 CloudWatch/EventBridge 事件触发。 It will read all the files and will push all the object details need to be processed in SNS.它将读取所有文件并推送所有需要在 SNS 中处理的 object 详细信息。

Lambda2 will be triggered by SNS and it will process all the files separately. Lambda2 将由 SNS 触发,它将单独处理所有文件。

Is the particular location(prefix) in S3 fixed or can be changed during the lifetime of the application? S3 中的特定位置(前缀)是固定的还是可以在应用程序的生命周期内更改?

Depending on your use cases, you might want to hard code the prefix in the lambda which is triggered by cloudwatch event, or store the prefix in a database like dynamodb and use lambda to query the database after the lambda is triggered by cloudwatch event.根据您的用例,您可能希望对由 cloudwatch 事件触发的 lambda 中的前缀进行硬编码,或者将前缀存储在 dynamodb 之类的数据库中,并在 lambda 之后使用 Z945F3FC449518A73CZ 查询数据库。

After that you have 2 options:之后,您有 2 个选择:

  1. Use the same lambda which is triggered by cloudwatch event to process the files in S3.使用由 cloudwatch 事件触发的相同 lambda 来处理 S3 中的文件。

  2. Use the lambda which is triggered by cloudwatch event to read the files in S3 and pass the object details to a queue.使用由 cloudwatch 事件触发的 lambda 读取 S3 中的文件并将 object 详细信息传递到队列。 Another lambda function can be used to query the queue to further process the files.另一个 lambda function 可用于查询队列以进一步处理文件。 The queue can be SNS or SQS depending on the use case.队列可以是 SNS 或 SQS,具体取决于用例。

Have a look at the architecture here: https://youtu.be/43PhZC3WD8s?t=967 for option 2. Not exactly the same use case, but can be useful!在这里查看架构: https://youtu.be/43PhZC3WD8s?t=967用于选项 2。不完全相同的用例,但可能有用!

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

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