edmamerto
edmamerto

Reputation: 8165

AWS "state file" solution for Lambda

I'm using a library in lambda where a "state file" is persisted

This is what it looks like in code:

def initialize
  @config = '/tmp/dogscaler.yaml'
  @state = self.load
end

If you need to look at the whole logic

My issue is that, this won't work in lambda (it being serverless). I'm trying to look for a solution where I don't have to change the logic in how the file is read and modifed.

Can this be achieved with S3?

Would something like this pseudo code work?

read s3://path/to/file
write s3://path/to/file

Are there better solutions to S3?

Additional Context

The file is needed for a cooldown period logic. Every time the application runs, it would check a time stamp from that file to make a judgement on wether to change an element or not. File is less than 1KB.

Upvotes: 0

Views: 111

Answers (1)

Jason Wadsworth
Jason Wadsworth

Reputation: 8887

Based on the updated information you could store the data in a number of places.

S3 would be perfectly fine, but might be overkill if this is all you're using it for.

The same can be said of DynamoDB.

Parameter Store is a solid option for your use case. Bear in mind that if you are calling it often you may need to increase your TPS limit. It doesn't sound like that will be an issue for you. Also keep in mind that there is no protection here for multiple instances of your Lambda function writing to the parameter at the "same time." The last write will win. If you need to protect against that DynamoDB is probably the best option.

Upvotes: 3

Related Questions