Reputation: 473
I have a AWS lambda function running some code and then saving a json to a s3 bucket.
Currently, my formatting is using the datetime package to grab the current date.
now = str(datetime.today())
I am then formatting the csv to
'payrollcompensation_streams/{}_{}.json'.format('pega_payrollcompensation_raw',now))
What I want to do is everytime this AWS Lambda function runs generate an unique key of an integer instead of a datetime.
Instead of this: pega_payrollcompensation_raw_2020-03-05 00:00:00.0000
This: pega_payrollcompensation_raw_1
Then the next time
pega_payrollcompensation_raw_2
Upvotes: 0
Views: 377
Reputation: 634
In case of using Lambda for this task you need to save state somewhere. Best fit for your case is DynamoDB. You need to set some sort of counter there and receive value from counter first. Be careful with concurrency.
Upvotes: 1
Reputation: 1572
How about using the timestamp()
method for your unique key?
For example:
>>> datetime.today().timestamp()
1583449231.642402
Upvotes: 1