Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to store single value in AWS Lambda

I have a Lambda that is generating and returning a value. This value can expire. Therefore I need to check the values validity before returning. As generating is quite expensive (taken from another service) I'd like to store the value somehow.

What is the best practice for storing those 2 values (timestamp and a corresponding value)?

  • DynamoDB, but using a database service for 2 values seems to be a lot of overhead. There will never be more items; The same entry will only get updated.
  • I thought about S3, but this would also imply creating a S3-Bucket and storing one object containing the information, only for this 2 values (but probably the most "lean" way?)
  • Would love to update Lambdas configuration in order to update the environment variables (but even if this is possible, its probably no best practice?! Also not sure about inconsistencies with Lambda runtimes...)

Whats best practice here? Whats the way to go in terms of performance?

like image 519
cvoigt Avatar asked Feb 05 '18 20:02

cvoigt


People also ask

What is the best way to store the data used across multiple Lambda functions?

Amazon EFS for Lambda Amazon EFS is a fully managed, elastic, shared file system that integrates with other AWS services. It is durable storage option that offers high availability. You can now mount EFS volumes in Lambda functions, which makes it simpler to share data across invocations.

Should Lambda be single responsibility?

One of the important things to keep in mind when developing lambdas is that they must be single-purpose. Deriving from the Single Responsibility Principle (SRP), “each lambda must be non-trivial, have a unique responsibility and encapsulate an axis of change”. A lambda should be non-trivial.

Can we store data in Lambda?

Today, we are announcing that AWS Lambda now allows you to configure ephemeral storage ( /tmp ) between 512 MB and 10,240 MB. You can now control the amount of ephemeral storage a function gets for reading or writing data, allowing you to use AWS Lambda for ETL jobs, ML inference, or other data-intensive workloads.


1 Answers

Use DynamoDB. There is no overhead for "running a database" -- it is a fully-managed service. You pay only for storage and provisioned capacity. It sounds like your use-case would fit within the Free Usage Tier.

Alternatively, you could use API Gateway with a cache setting so that it doesn't even call the Lambda function unless a timeout has passsed.

like image 153
John Rotenstein Avatar answered Nov 07 '22 04:11

John Rotenstein