问题
I am trying to pass a unix timestamp into API get request as a parameter to another system to grab data. The parameter needs to be the last time the AWS Lambda ran. I need to somehow store the last time the AWS lambda function has ran into maybe an s3 bucket and also recover that timestamp. So I can pass that value along into the next run.
Anyone have any ideas on how to do something like this?
回答1:
Lambda does not store any last run time between invocations (especially as its possible there could be concurrent invocations of your Lambda at the same time).
Depending on the use case if you want your Lambda to both read and write DynamoDB will probably be your best choice, although you should be aware of the following:
- Reads and writes use credits, if you're read and write heavy you will need to consider pricing and enable autoscaling if your load varies.
- By default reads are eventually consistent, if your writes must be accurate you will want to use strongly consistent reads.
As an alternative you could store the value as a parameter store value, it is limited 1000 operations per second so if you are not using frequent requests this will provide a very simple implementation.
If you do not need the information within the Lambda itself, you can get this information by filtering the CloudWatch logs that are produced by your Lambda. This would not be advisable in your Lambda itself as duration would span longer than either of the above options.
回答2:
A quick database you could access from an AWS Lambda function is AWS Systems Manager Parameter Store.
You can store simple information such as configuration settings, URLs to databases and even... the last execution time!
IAM permissions can be used to limit access to specific parameters.
回答3:
AWS Lambda stores many metrics on each function, including invocation time. Are you using boto3 or some other SDK?
来源:https://stackoverflow.com/questions/63017476/does-aws-lambda-store-last-run-time