The goal: show Azure Function is connections with other services
-
Login to azure
az login
and select Subscriptionaz account set -s $SUBSCRIPTION_ID
-
Change working directory to:
cd src/terraform/06-core-services-faas
-
Create
terraform.tfvars
file. This file contains your unique properties for the rest of terraform configuration. You can use a sample generator script:../generate_tfvars.sh
-
Review proposed terraform configuration:
- Event Grid
- Storage Account Table
- FaaS itself integrated with two above
-
Provision Azure components via terraform
terraform init terraform apply
Disclaimer: current terraform config cannot complete event-grid subscription, as it will require deployed function. Check "Deploy Function" section and then rerun
terraform apply
-
Parse terraform output to environment variables that will be picked up by azure-function locally:
export AzureWebJobsStorage=$(terraform output -raw azure_web_jobs_storage)
export eventGridTopicEndpoint=$(terraform output -raw events_topic_endpoint)
export eventGridTopicKey=$(terraform output -raw events_topic_key)
export StorageAccountConnectionString=$(terraform output -raw storage_account_connection_string)
export storageAccountTableName=$(terraform output -raw storage_account_tablename)
export FUNCTION_APP_NAME=$(terraform output -raw azure_function_name)
-
Change working directory to function sources:
cd ../../az_func
-
Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
-
Deploy function to Azure:
func azure functionapp publish $FUNCTION_APP_NAME --python
. Note, it takes some time to finish the process. -
Run locally
-
Run the application:
func start --python
. -
Insert events from another terminal:
echo $(date) | xargs -I{} curl -d '{"name":"the first", "time":"{}"}' -X POST http://localhost:7071/api/HttpToEventGrid
.
-
-
Ingest events
# Get function code
func azure functionapp list-functions $FUNCTION_APP_NAME --show-keys
# Get function URL from previous command or from Code+Test view, for example:
FUNCTION_URL=https://cloud23-huvn-func.azurewebsites.net/api/httptoeventgrid?code=pkyeU6XDc5GH8Ig6EEcPolpkuTP447c8jG7hd8_u3Nc6AzFuiiTtjQ==
echo $(date) | xargs -I{} curl -d '{"name":"the first", "time":"{}"}' -X POST $FUNCTION_URL
-
Review and Feedback:
- Review setup process
- Consider failure strategies
- Propose mitigations: poison queue, jitter, retries
Remove created resources: cd - && terraform destroy