Azure Functions : Article 07
Hello Everyone this is my Seventh Article in Azure Series. If you missed to read my Azure App services article please click here.
What is Azure Function?
Azure Functions allows you to run small pieces of code (called “functions”) without worrying about application infrastructure. With Azure Functions, the cloud infrastructure provides all the up-to-date servers you need to keep your application running at scale.
A function is “triggered” by a specific type of event. Supported triggers include responding to changes in data, responding to messages, running on a schedule, or as the result of an HTTP request.
- Serverless applications
- Choice of language
- Pay-per-use pricing model
- Bring your own dependencies
- Integrated security
- Simplified integration
- Flexible development
- Stateful serverless architecture
For more : click here
Create a function in Azure using Visual Studio Code
In this article, you use Visual Studio Code to create a Java function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
Configure your environment
Before you get started, make sure you have the following requirements in place:
- An Azure account with an active subscription. Create an account for free.
- The Java Developer Kit, version 8.
- Apache Maven, version 3.0 or above.
- Visual Studio Code on one of the supported platforms.
- The Java extension pack
- The Azure Functions extension for Visual Studio Code.serverless environment of Azure Functions.
Create your local project
Step 1 : Add Azure Function Extension in visual studio code
Step 2: Choose the Azure icon in the Activity bar, then in the Azure: Functions area, select the Create new project… icon.
- Choose a directory location for your project workspace and choose Select.Choose a directory location for your project workspace and choose Select.
- Select a language for your function project: Choose
- Provide a group ID: Choose
- Provide an artifact ID: Choose
- Provide a version: Choose
- Provide a package name: Choose
- Provide an app name: Choose
- Select how you would like to open your project: Choose
Add to workspace.
Run the function locally
Visual Studio Code integrates with Azure Functions Core Tools to let you run this project on your local development computer before you publish to Azure.
- To call your function, press F5 to start the function app project. Output from Core Tools is displayed in the Terminal panel.
- If you haven’t already installed Azure Functions Core Tools, select Install at the prompt. When the Core Tools are installed, your app starts in the Terminal panel. You can see the URL endpoint of your HTTP-triggered function running locally.
3. With Core Tools running, navigate to the following URL to execute a GET request, which includes
?name=Functions query string.
4. Information about the request is shown in Terminal panel.
5. Press Ctrl + C to stop Core Tools and disconnect the debugger.
Sign in to Azure
- When prompted in the browser, choose your Azure account and sign in using your Azure account credentials.
- After you’ve successfully signed in, you can close the new browser window. The subscriptions that belong to your Azure account are displayed in the Side bar.
Publish the project to Azure
In this section, you create a function app and related resources in your Azure subscription and then deploy your code.
- Choose the Azure icon in the Activity bar, then in the Azure: Functions area, choose the Deploy to function app… button.
Run the function in Azure
Back in the Azure: Functions area in the side bar, expand the new function app under your subscription. Expand Functions, right-click (Windows) or Ctrl + click (macOS) on HttpExample, and then choose Copy function URL.
Paste this URL for the HTTP request into your browser’s address bar, add the
name query string as
?name=Functions to the end of this URL, and then execute the request. The URL that calls your HTTP-triggered function should be in the following format:
Reference : click here
This is the end of this article. See you in the next article..!
Next Article: Azure Database for MySQL server