简体   繁体   English

从 AWS Lambda 调用中保存数据的最佳方法?

[英]Best method to persist data from an AWS Lambda invocation?

I use AWS Simple Email Services (SES) for email. I've configured SES to save incoming email to an S3 bucket, which triggers an AWS Lambda function. This function reads the new object and forwards the object contents to an alternate email address. I use AWS Simple Email Services (SES) for email. I've configured SES to save incoming email to an S3 bucket, which triggers an AWS Lambda function. This function reads the new object and forwards the object contents to an alternate email address.

I'd like to log some basic info.我想记录一些基本信息。 from my AWS Lambda function during invocation -- who the email is from, to whom it was sent, if it contained any links, etc.在调用期间来自我的 AWS Lambda function - email 来自谁,发送给谁,是否包含任何链接等。

Ideally I'd save this info.理想情况下,我会保存此信息。 to a database, but since AWS Lambda functions are costly (relatively so to other AWS ops.), I'd like to do this as efficiently as possible.到数据库,但由于 AWS Lambda 函数的成本很高(相对于其他 AWS 操作而言),我想尽可能高效地执行此操作。

I was thinking I could issue an HTTPS GET request to a private endpoint with a query-string containing the info.我在想我可以使用包含信息的查询字符串向私有端点发出 HTTPS GET 请求。 I want logged.我要登录。 Since I could fire my request async.因为我可以异步触发我的请求。 at the outset and continue processing, I thought this might be a cheap and efficient approach.在开始并继续处理时,我认为这可能是一种廉价且高效的方法。

Is this a good method?这是一个好方法吗? Are there any alternatives?还有其他选择吗?

My Lambda function fires irregularly so despite Lambda functions being kept alive for 10 minutes or so post-firing, it seems a database connection is likely slow and costly since AWS charges per 100ms of usage.我的 Lambda function 会不规律地触发,因此尽管 Lambda 函数在触发后保持活动状态 10 分钟左右,但数据库连接似乎很慢且成本高,因为 AWS 每 100 毫秒使用一次收费。

Since I could conceivable get thousands of emails/month, ensuring my Lambda function is efficient is paramount to cost.由于我可能每月收到数千封电子邮件,因此确保我的 Lambda function 高效对成本来说至关重要。 I maintain 100s of domain names so my numbers aren't exaggerated.我维护着 100 个域名,所以我的数字没有被夸大。 Thanks in advance.提前致谢。

I do not think that thousands per emails per month should be a problem, these cloud services have been developed with scalability in mind and can go way beyond the numbers you are suggesting.我认为每月每封电子邮件数以千计应该不是问题,这些云服务的开发考虑了可扩展性,并且可以 go 超出您建议的数量。

In terms of persisting, I cannot really understand - lack of logs, metrics - why your db connection would be slow.在坚持方面,我无法真正理解 - 缺乏日志、指标 - 为什么你的数据库连接会很慢。 From the moment you use AWS, it will use its own internal infrastructure so speeds will be high and not something you should be worrying about.从您使用 AWS 的那一刻起,它就会使用自己的内部基础设施,因此速度会很快,您不必担心。

I am not an expert on billing but from what you are describing, it seems like using lambdas + S3 + dynamoDB is highly optimised for your use case.我不是计费方面的专家,但根据您的描述,使用 lambdas + S3 + dynamoDB 似乎针对您的用例进行了高度优化。

From the type of data you are describing (email data) it doesn't seem that you would have neither a memory issue (lambdas have mem constraints which can be a pain) or an IO bottleneck.从您描述的数据类型(电子邮件数据)来看,您似乎既没有 memory 问题(lambdas 有 mem 约束,这可能很痛苦)也没有 IO 瓶颈。 If you can share more details on your memory used during invocation and the time taken that would be great.如果您可以分享有关调用期间使用的 memory 的更多详细信息以及所花费的时间,那就太好了。 Also how much data you store on each lambda invocation.还有你在每次 lambda 调用时存储了多少数据。

I think you could store jsonified strings of your email data in dynamodb easily, it should be pretty seamless and not that costly.我认为您可以轻松地将 email 数据的 jsonified 字符串存储在 dynamodb 中,它应该是非常无缝的并且不会那么昂贵。

Have not used (SES) but you could put a trigger on DynamoDB whenever you store a record, in case you want to follow up with another lambda. You could combine S3 + dynamoDB.尚未使用 (SES),但您可以在存储记录时在 DynamoDB 上放置一个触发器,以防您想跟进另一个 lambda。您可以结合使用 S3 + dynamoDB。 When you store a record, simply upload a file containing the record to a new S3 key and update the row in DynamoDB with a pointer to the new S3 object存储记录时,只需将包含该记录的文件上传到新的 S3 密钥,并使用指向新 S3 的指针更新 DynamoDB 中的行 object

DynamoDB + S3 动态数据库 + S3

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

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