Search code examples
amazon-web-servicesamazon-s3aws-lambdaamazon-dynamodbserverless

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?


Solution

  • 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.