Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 3.43 KB

File metadata and controls

97 lines (72 loc) · 3.43 KB

Step-by-Step Guide: Deploying an Azure Function as an API Endpoint

1. Prepare Your Function App

  • Have your code ready (e.g., Python, C#, JavaScript).
  • Ensure you have the necessary Azure Function project structure.
  • Install Azure CLI on your machine.
  • Log in to your Azure account with:
    az login

2. Create an Azure Function App in the Portal

  1. Go to the Azure Portal.

  2. Create a Resource:

    • Click Create a resource.
    • Search for Function App and select it.
    • Click Create.
  3. Configure Basics:

    • Subscription: Choose your subscription.
    • Resource Group: Select or create a new resource group.
    • Function App Name: Enter a globally unique name.
    • Region: Choose a region close to your users.
    • Runtime Stack: Select your language (e.g., Python, Node.js, .NET).
    • Version: Pick the version matching your code.
    • Operating System: Windows or Linux (Linux is common for Python).
  4. Hosting Tab:

    • Storage Account: Create a new or use an existing one.
    • Leave other settings as default for most scenarios.
  5. Review + Create:

    • Review all settings.
    • Click Create to deploy the Function App.

3. Deploy Your Code

You can use either VS Code, Azure CLI, or directly from the Portal. Below is the Azure CLI method:

  • Navigate to your function app project folder.

  • Initialize the project (if not done):

    func init --worker-runtime python
    func new  # to create a function (e.g., HTTP trigger)
  • Deploy to Azure:

    func azure functionapp publish <YourFunctionAppName>

4. Configure the Function as an API Endpoint

  • By default, an HTTP Triggered function becomes a REST API endpoint.
  • After deployment, go to your Function App in Azure Portal.
  • Open "Functions" in the sidebar.
  • Select your function (e.g., HttpTrigger1).
  • Go to "Code + Test" to verify code.
  • Click "Get Function URL" at the top right.
  • Copy the URL—this is your live API endpoint.
Step Action
Create app Use Portal to create a Function App
Prepare code Add HTTP Trigger in your code project
Deploy Use VS Code or func azure functionapp publish
Test Get Function URL, send a request (use Postman or curl)

5. Test Your Endpoint

  • Use Postman or curl to send a request:

    curl -X POST <FunctionURL> -H "Content-Type: application/json" -d '{"key":"value"}'
  • Confirm the response matches your expected output.

6. Additional Configuration

  • Authentication: Enable Authentication/Authorization in the Portal if needed.
  • CORS: Set allowed origins under "CORS" if the API is called from browsers.
  • Monitoring: Use Application Insights (enable during setup or later) for logging and diagnostics.

7. Secure Your Function

  • Use function/API keys for private endpoints.
  • Store secrets (e.g., your Cognitive Services keys) in Azure Key Vault or environment settings in "Configuration".

8. CI/CD Option (Optional)

  • For advanced workflows, connect your GitHub repo or Azure Repo in the "Deployment Center" of your Function App for automated deployments.

Following these steps will provide you with a live, scalable Azure Function endpoint ready for use as an API in your AI-powered application.

Sources