Create an API with Azure Function that displays your resume information in json.
- GitHub for Version control.
- GitHub Actions for CI/CD pipeline.
- Azure Functions to deploy our API.
- Azure Blob Storage to store our resume.
- .NET 6 as our programming framework for our API.
- Optional: GitHub Codespaces as our development environment.
- Bicep for our Infrastructure as Code.
- Azure account
- GitHub account
- I've provided a sample .json file based on the Json resume
For local developer environment
- VS Code
- Docker
- VS Code Dev Container Extension
NOTE At the moment, GitHub Free for personal accounts comes with 15 GB of Codespaces storage and 120 Core hours per month. Read more about pricing here
- Fork the repository so you can have your own copy of it.
- FOR CLOUDSPACES: Click on the
Code
button, click onCodespaces
tab, and click onCreate Codespaces on main
. I've provided adevcontainer.json
file with the configuration needed for this project. - Once your Codespace has loaded, in the Explorer, expand the
src
folder and renamelocal.settings.sample.json
tolocal.settings.json
- FOR LOCAL DEV: Clone the code, open it with VS Code and Launch in the dev container. More info here
- In the Terminal, type
az login --use-device-code
to log into your Azure account from the az cli in your Codespace. - In the Terminal, type
az account list --output table
to get a list of Azure subscriptions you have available to you and make note of the name you want to use. - In the Terminal, type
az account set --name "name-of-subscription"
with the name of the subscription you want to use. - In the Terminal, type
az account show
and make sure it's set to the subscription you want to work in.
NOTE: I've set the resource group name to be
rg-serverlessresumeapi
- I've provided Infrastructure as Code (IaC) files, you can find them in the
infra
folder. Now we need to use those files to create a deployment in Azure, in the Terminal, type:az deployment sub create --template-file ./infra/main.bicep -l <your-region>
- In the Terminal, run the following command to see the values for your storage account name and function:
az deployment group show -g rg-serverlessresumeapi -n resources --query properties.outputs
- Now let's save that output into individual variables. Run the Azure CLI command and capture the output:
output=$(az deployment group show -g rg-serverlessresumeapi -n resources --query properties.outputs)
- Since the output has several values, we need to arse the output and store each value in a variable
functionAppName=$(echo $output | jq -r '.functionAppName.value') functionUri=$(echo $output | jq -r '.functionUri.value') storageAccountName=$(echo $output | jq -r '.storageAccountName.value')
- Now we can Echo (print to screen) the variables to verify
echo "Function App Name: $functionAppName" echo "Function URI: $functionUri" echo "Storage Account Name: $storageAccountName"
- Upload
myresume.json
to that newly created blob container.az storage blob upload --account-name $storageAccountName --container-name resume --name myresume.json --file myresume.json
- In your
local.settings.json
add the Storage Account Connection String to theAzureWebJobsStorage
value. You can get that value by running this command:az storage account show-connection-string --name $storageAccountName --resource-group rg-serverlessresumeapi
- You can now run and debug (F5) your Function in your environment or run this command in the terminal:
cd src func start host
- In the .github folder, edit your
build.yml
and update theAZURE_FUNCTIONAPP_NAME
value with the name of your function app. - We'll need to get our Function's Publish Profile, run the following command in the terminal and copy the output:
az functionapp deployment list-publishing-profiles --name $functionAppName --resource-group rg-serverlessresumeapi --xml
- In your GitHub repo, go to settings > secrets and variables > actions > create a secret named
AZURE_FUNCTIONAPP_PUBLISH_PROFILE
with the contents of your publish profile you just copied. - Head to Actions tab on your Repo and manually run the workflow.
- Once it's complete. Your resume api is now in production. We can view it in 3 ways:
- Using curl in the terminal:
curl $functionUri/getresume
- Using the browser: open a new tab with your function URI and add
/api/getresume
at the end. - Use the thunderclient extension in VS Code with your function URI and add
/api/getresume
at the end.
- Using curl in the terminal: