0% found this document useful (0 votes)
24 views

Week 6 - Mini Project Assignment 1

Uploaded by

pilankarsandy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Week 6 - Mini Project Assignment 1

Uploaded by

pilankarsandy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Mini Project Assignment: Building and Deploying a Serverless API with

Azure Functions and Azure DevOps

Objective

In this mini project, students will create a serverless API using Azure Functions and automate
its deployment using Azure DevOps. The project will help students understand how to build
serverless applications and implement continuous integration and continuous deployment
(CI/CD) pipelines.

Project Overview

 Create a serverless API using Azure Functions


 Implement a CI/CD pipeline using Azure DevOps to automate the deployment of
the Azure Function

Prerequisites

 Basic understanding of Azure Functions and Azure DevOps


 Azure account
 Azure DevOps account
 Visual Studio Code or another code editor

Step-by-Step Instructions

Part 1: Creating the Azure Function

1. Set Up Your Local Environment


o Install Azure Functions Core Tools.
o Install Azure CLI.
o Install Visual Studio Code and the Azure Functions extension.
2. Create a New Azure Function Project
o Open Visual Studio Code.
o Open the command palette (Ctrl+Shift+P) and select Azure Functions:
Create New Project....
o Select a folder for your project.
o Choose a language (e.g., JavaScript, Python, C#).
o Select HTTP trigger template.
o Name your function (e.g., HttpExample).
o Set the namespace to Anonymous.
3. Implement the Function
o Modify the generated code in the HttpExample function to return a custom
message.
o Example (JavaScript):

module.exports = async function (context, req) {


context.log('HTTP trigger function processed a request.');
const name = req.query.name || (req.body && req.body.name);
const responseMessage = name
? `Hello, ${name}. This HTTP triggered function
executed successfully.`
: "This HTTP triggered function executed successfully.
Pass a name in the query string or in the request body for a
personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
};

4. Test the Function Locally


o Open a terminal in Visual Studio Code.
o Run the function locally using func start.
o Open a browser and navigate to
http://localhost:7071/api/HttpExample?name=YourName to see the
function in action.
5. Deploy the Function to Azure
o Use the Azure Functions extension in Visual Studio Code.
o Click on the Azure icon in the Activity bar, then right-click on your function
app and select Deploy to Function App....
o Follow the prompts to create a new function app in Azure and deploy your
code.

Part 2: Setting Up Azure DevOps

1. Create a New Project in Azure DevOps


o Navigate to your Azure DevOps account.
o Click on New Project and provide a name (e.g., ServerlessAPIProject).
2. Set Up a Git Repository
o In your new project, navigate to Repos and initialize a new repository.
o Clone this repository to your local machine and add your Azure Function
project files to it.
o Commit and push the changes to the repository.
3. Create a CI/CD Pipeline
o Navigate to Pipelines in your Azure DevOps project.
o Click on New pipeline.
o Select Azure Repos Git as the code repository.
o Configure the pipeline by selecting the repository and following the prompts
to set up the pipeline.
4. Define the Pipeline YAML
o Create a file named azure-pipelines.yml in the root of your repository.
o Add the following YAML configuration:

trigger:
branches:
include:
- main

pool:
vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
addToPath: true

- checkout: self

- task: AzureFunctionApp@1
inputs:
azureSubscription: 'Your Azure Subscription'
appType: 'functionApp'
appName: 'Your Function App Name'
package: '$(System.DefaultWorkingDirectory)/**/*.zip'

5. Run the Pipeline


o Commit and push the azure-pipelines.yml file to your repository.
o Navigate back to Pipelines in Azure DevOps and manually run the pipeline
for the first time.
o The pipeline will build your Azure Function project and deploy it to Azure.

Part 3: Verification and Testing

1. Verify the Deployment


o Navigate to the Azure portal and find your deployed Function App.
o Get the Function App URL and test it in a browser:
https://<YourFunctionAppName>.azurewebsites.net/api/HttpExample
?name=YourName.
2. Automated Deployment
o Make a change to your function code locally.
o Commit and push the changes to the main branch.
o Verify that the CI/CD pipeline runs automatically and deploys the updated
function.

Deliverables

1. Source Code: The complete source code of your Azure Function project in the Git
repository.
2. Pipeline Configuration: The azure-pipelines.yml file in the repository.
3. Documentation: A brief report explaining the steps taken, issues faced, and how they
were resolved.

Grading Criteria

 Correctness: The function performs as expected and returns the correct response.
 Pipeline Configuration: The CI/CD pipeline is correctly set up and functional.
 Documentation: Clear and comprehensive documentation of the process.
 Code Quality: Code is clean, well-commented, and follows best practices.

You might also like