Search This Blog

Wednesday, June 28, 2023

Azure Function

 

Introduction:

Sometime it happens that you want to write small piece of code and it should be accessible from outside but you may not have infrastructure ready for it. In that situation you can write a function which can be called from anywhere. Azure function provides required infrastructure for code you need to write and you can make it available within few minutes.

You can use Azure functions where you code does not include any complex logic. Azure functions can be used for very small pieces of code which can be invoked via any triggered events.

You can choose your language to write the code like C#, F#, Node.js, Python or PHP. Azure Functions lets you develop server less applications on Microsoft Azure.

Description:

1. Features:

Azure function provides the below features:

  • Choice of language – We can write functions using C#, F#, Node.js, Python, PHP, batch, bash, or any executable.
  • Pay-per-use pricing model – Pay only for the time spent running your code.
  • Bring your own dependencies – we can include other library as well if needed.
  • Integrated security – Protect HTTP-triggered functions with OAuth providers such as Azure Active Directory, Facebook, Google, Twitter, and Microsoft Account.
  • Simplified integration – Easily leverage Azure services and software-as-a-service (SaaS) offerings.
  • Flexible development – Code your functions right in the portal or set up continuous integration and deploy your code through GitHub, Visual Studio Team Services.

2. Function Task:

Functions provides templates to get you started with key scenarios,

  • Blob Trigger
  • EventHubTrigger
  • Generic webhook
  • GitHub webhook
  • HTTPTrigger
  • QueueTrigger
  • ServiceBusQueueTrigger
  • ServiceBusTopicTrigger
  • TimerTrigger

Create your first function:

  1. Prerequisites:

    Windows Azure Subscription – you can also subscribe for a free trial of Windows Azure from URL.

  2. Add Function Apps
    • In order to host your code, you must have a function app created in the Azure.
    • Login to the azure portal and click on the +(plus) sign
    • Select the function app and provide the required details

  3. Provide the Azure function details as shown below.

    Provide all the required field value and click create, you will able to see below screen,

  4. Create function:
    • Click on the plus sign as shown
    • Select the httptriger-csharp
    • Provide a unique name to the function and click create
    • Now you are read with the function that can be access from anywhere.
    • This is the template you can write your own code, we will work with the sample code that generated automatically.
  5. Let’s test the function from outside.
    • Copy the url form the console as show
  6. You will get the code url that can be called from any API tester application, lets we called it from the Postman application.

    As you can see in the below screen, I called the function from Postman and in out window you will find that it is showing message. It shows some validation message because I have not provided the required fields.

  7. I provided the name you will find that output shows the name with greeting.
  8. View the function logs

No comments:

Post a Comment