In this section, we'll trigger an Azure Function from a console application. We'll integrate an existing command-line application with our new cloud architecture. To ensure it works correctly, you'll need to have the code repository downloaded. Let's begin by implementing the following steps:
- Open the project called PersonalFinanceCLIApp and take a look around.
Refer to the following screenshot:
Navigate to https://goo.gl/q79fPe to access the code.
- Add an HttpClient and your API key as static variables.
Get your API key by going to your function in the portal and clicking on the Keys tab.
Refer to the following screenshot:
Navigate to https://goo.gl/E88BMn to access the code.
- Create an async static function called BackupTransaction that takes a transaction object. In the function, copy and paste the code from our serverless client POST action. Refer to the following screenshot:
- Make a call to BackupTransactions and pass the transaction into it.
- Run the CLI app; it should be just as responsive as it was previously, because the asynchronous code is executing on a separate thread.
You have successfully written an application that backs transactions up to the Cosmos DB.
Thirdly, if you have a fairly well-architected application written in a programming language that your development team can cope with, then you can progressively shift functionality to serverless functions without breaking the application. This allows you to split the work up to replace the application entirely, and, once you have this data flowing through serverless functions, you can start extending this application into the rest of your serverless architecture.
This functionality will then be available for other services to use, which is particularly useful for intensive, business-specific calculations. It will also scale infinitely, allowing you to free up computing power from your client machines (this is very useful for code running on old servers, and so on).