Reputation: 587
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)?
Whats best practice here? Whats the way to go in terms of performance?
Upvotes: 24
Views: 10509
Reputation: 1
Dynamodb would be a better option compared to the other ways of storage by AWS. Dynamodb is optimized for low-latency, high-throughput access to data, making it suitable for scenarios requiring fast data retrieval and updates for that single value.
Systems Manager Parameter Store can handle moderate workloads and offers low latency for individual API requests, it may not be as performant as DynamoDB for scenarios requiring high-frequency data access. Though it offers a cost-effective solution for managing configuration data and secrets, the cost may increase with high API request volumes or frequent parameter updates.
You can take a look at this link for other storage options provided by AWS:- https://aws.amazon.com/blogs/compute/choosing-the-right-solution-for-aws-lambda-external-parameters/
Upvotes: 0
Reputation: 269480
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.
Upvotes: 18
Reputation: 231
Just set the environment variable with a value and a date. Then check the date every time lambda is executed.
https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionConfiguration.html
Upvotes: -4
Reputation: 14829
You could consider AWS Parameter Store
AWS Systems Manager Parameter Store provides secure, hierarchical storage for configuration data management and secrets management. You can store data such as passwords, database strings, and license codes as parameter values. You can store values as plain text or encrypted data. You can then reference values by using the unique name that you specified when you created the parameter. Highly scalable, available, and durable, Parameter Store is backed by the AWS Cloud. Parameter Store is offered at no additional charge.
Upvotes: 12
Reputation: 111366
For cases like this I would use some fast in-memory data store, like Redis or Memcached:
And luckily there is Amazon ElastiCache:
which is managed Redis and Memcached, but you don't need to use it for your use case - you could easily use Redis on your own EC2, or you could use an external service like Compose that also supports instances inside of Amazon data centers:
Lots of ways to use it but I would certainly use Redis, especially for simple cases like this.
Upvotes: -3