Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

az storage blob subscribe #23

Open
noelbundick opened this issue Nov 10, 2018 · 0 comments
Open

az storage blob subscribe #23

noelbundick opened this issue Nov 10, 2018 · 0 comments

Comments

@noelbundick
Copy link
Owner

noelbundick commented Nov 10, 2018

I want to use EventGrid to subscribe to blob created events. The current process is involved. Basically I want to script these steps:

FUNCTION="name_of_my_function_app"
FUNCTION_RG="function_resource_group"
STORAGE_ACCT="storage_acct_to_subscribe_to"

STORAGE_ACCT_ID=$(az storage account show -n $STORAGE_ACCT --query id -o tsv)
FUNCTION_USERNAME=$(az webapp deployment list-publishing-profiles -n $FUNCTION -g $FUNCTION_RG --query "[?publishMethod=='MSDeploy'].userName" -o tsv)
FUNCTION_PASS=$(az webapp deployment list-publishing-profiles -n $FUNCTION -g $FUNCTION_RG --query "[?publishMethod=='MSDeploy'].userPWD" -o tsv)
FUNCTION_TOKEN=$(curl -s -u ${FUNCTION_USERNAME}:${FUNCTION_PASS} -X GET https://$FUNCTION.scm.azurewebsites.net/api/functions/admin/token | jq -r .)
MASTER_KEY=$(curl -s -H "Authorization: Bearer $FUNCTION_TOKEN" -X GET https://$FUNCTION.azurewebsites.net/admin/host/systemkeys/_master | jq -r .value)
az eventgrid event-subscription create --resource-id $STORAGE_ACCT_ID --name mycontainer --included-event-types 'Microsoft.Storage.BlobCreated' --endpoint "https://$FUNCTION.azurewebsites.net/runtime/webhooks/eventgrid?functionName=MyFunctionName&code=$MASTER_KEY"

Update - slightly less hacky steps:

ARM_TOKEN=$(az account get-access-token --query accessToken -o tsv)
SYSTEM_KEY=$(curl -s -H "Authorization: Bearer $ARM_TOKEN" "https://management.azure.com$FUNCTION_ID/hostruntime/admin/host/systemkeys/eventgrid_extension?api-version=2018-02-01" | jq -r .value)
az eventgrid event-subscription create --resource-id $STORAGE_ACCT_ID --name custodianlogs --included-event-types 'Microsoft.Storage.BlobCreated' --subject-ends-with 'resources.json.gz' --endpoint "https://$FUNCTION.azurewebsites.net/runtime/webhooks/eventgrid?functionName=TransformCustodianLogs&code=$SYSTEM_KEY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant