First of all, step one is to get notified that the function is about to be aborted. You can use the CancellationToken for that:
A function can accept a CancellationToken parameter, which enables the operating system to notify your code when the function is about to be terminated. You can use this notification to make sure the function doesn't terminate unexpectedly in a way that leaves data in an inconsistent state.
Now you know that the function is about to be aborted you can react on that. However, you have just 10 seconds before the function is aborted. So that gives you limited time to complete the message processing.
One option is to cancel further processing and rollback any changes, if that is faster than completing the message, so the message get visible again for other instances that are alive to process.