An HTTP endpoint for polling Mailchimp subscriber numbers for an LaMetric Time device. Designed to run on Azure Functions as an HTTP endpoint.
getConfirmedSubscribers: returns the confirmed subscribers from Mailchimp.- Type: HTTP trigger function.
Uses main.bicep to define the Azure resources.
Uses Azure ARM and Login GitHub actions to deploy.
AZURE_CREDENTIALS created as per the service principal
instructions:
az ad sp create-for-rbac --name "lamsubs-py - GitHub" --sdk-auth --role contributor \
--scopes /subscriptions/244fa449-6833-417a-9b8e-be5a66bdf344/resourceGroups/lamsubs-pyAZURE_FUNCTIONAPP_PUBLISH_PROFILE set up according to the docs.
Install Bicep which is used to compile the ARM template that manages the Azure resources.
# Assumes bc-totorobot-py resource group exists
bicep build ./main.bicep # generates main.json
az login
az deployment group create -f ./main.json -g lamsubs-py
func azure functionapp publish lamsubs-pyInstall the Azure Functions SDK and Azure CLI, then:
python3 -m venv .venvsource .venv/bin/activatepip3 install -r requirements.txt
# Set these values appropriately
export MAILCHIMP_API_KEY=""
export MAILCHIMP_LIST_ID=""
func host startcurl -i http://localhost:7071/api/getConfirmedSubscriberspython3 -m pytestCoverage reports:
python3 -m coverage run -m pytest
python3 -m coverage report --omit '.venv/*'These are substituted in as part of the deploy process and set in the GitHub repo secrets:
AZURE_CREDENTIALSdiscussed above.AZURE_FUNCTIONAPP_PUBLISH_PROFILEdiscussed above.MAILCHIMP_API_KEYfrom Mailchimp settings to be able to connect to the API.MAILCHIMP_LIST_IDfrom Audience settings.