Home > Uncategorized > Getting #AWS #Lambda timeout value at runtime in C#

Getting #AWS #Lambda timeout value at runtime in C#

If you have a Lambda function in C#, and you have a process that must complete before Amazon kills the process, say in the classic bank transfer example, where you debit one account and credit another. Both actions need to be taken atomically, or else the process should be rolled back.

In this case, you can’t have AWS killing your lambda function due to lack of time remaining, in mid-transaction. In this case, you’d have one account missing money, and no money in the payee account. In this case, it would be better to get a forewarning, that gives you X seconds to rollback the transaction, so that at least, you’re back to where you started.

So, what’s the magic command:

     var context = (ILambdaContext) HttpContext.Items["LambdaContext"];

This gives you an ILambdaContext Object, that contains data similar to the following;


Which gives you Remaining Time , and the Memory Limit, along with other values.

For other values relating to the Lambda, you should also check the Environment variables in your code.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: