Reputation: 152266
I'm creating a AWS Lambda function that talks with API using bearer token.
This token is generated automaticaly with OAuth endpoint and it has 24h of expiration time.
Because of that, I cannot store this token permanently. Asking for new token with each function invocation is also quite pointless.
What would be the most efficient way of dealing with time-limited token with serverless environment?
Upvotes: 2
Views: 1005
Reputation: 200850
I would store it somewhere outside of the Lambda function, where it can be retrieved by multiple Lambda execution environments. I've used a small DynamoDB table for this in the past, but I think the AWS Secrets Manager is the currently preferred place to store this sort of thing.
In addition to storing the OAuth token, store the timestamp when it was created. Then whenever you go to retrieve the token, right before you use it first check if it is getting close to the 24 hour timeout. If it is about to time out then have your process update it first and push the new token to wherever you are storing it.
Upvotes: 1