0

I have configured a blob storage event subscription to be raised when a file is uploaded into an Azure storage account and have created an EventGridTrigger type function app to consume the event.

[FunctionName("DataImport")]
public void Run([EventGridTrigger]EventGridEvent eventGridEvent)

I can set delivery properties within the portal subscription configuration which works for passing through a known reference that the function app needs.

However, I can find no documentation that tells me how to access the http request object within the function app. I have tried adding HttpRequest to the function parameters but that just fails when the function is initiated.

How can I access the delivery properties within the function app?

Andrew HB
  • 332
  • 1
  • 3
  • 11
  • Please check this article: http://dontcodetired.com/blog/post/Different-Ways-to-Parse-Http-Request-Data-in-Http-triggered-Azure-Functions –  Apr 13 '22 at 07:25
  • that article is HttpTrigger not EventGridTrigger? – Andrew HB Apr 13 '22 at 07:36

1 Answers1

0
  • Here is the example code snippet of HTTP Trigger function for event grid
   string eventGridValidationHeader = req.Headers.FirstOrDefault( x => string.Compare(x.Key,"Aeg-Event-Type", true) == 0).Value?.FirstOrDefault().Trim();

    // media type = application/json or application/cloudevents+json 
    string jsontext = null;
    var jtoken = JToken.Parse(await req.Content.ReadAsStringAsync());
    log.Info($"\n{jtoken.ToString(Newtonsoft.Json.Formatting.Indented)}");

    if (jtoken is JArray)
        jsontext = jtoken.SingleOrDefault<JToken>().ToString();
    else if (jtoken is JObject)
        jsontext = jtoken.ToString();

    var eventGridEvent = JsonConvert.DeserializeAnonymousType(jsontext, new { EventType = "", Data = new JObject()});
    if (string.IsNullOrEmpty(eventGridValidationHeader) || string.IsNullOrEmpty(eventGridEvent?.EventType) || eventGridEvent?.Data == null)
    {
        return req.CreateErrorResponse(HttpStatusCode.BadRequest, "No EventGrid message.");
    }

    if (eventGridValidationHeader == "SubscriptionValidation" && eventGridEvent.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent")
    {
        log.Verbose(@"Event Grid Validation event received.");
        return req.CreateResponse(HttpStatusCode.OK, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(new { validationResponse = ((dynamic)eventGridEvent.Data).validationCode })));               
    }

    #region Event Processing 

    // for testing a retry delivery policy 
    //return req.CreateResponse(HttpStatusCode.BadRequest, "Testing");

    #endregion

    return req.CreateResponse(HttpStatusCode.NoContent);    
}
  • for further details you can go through this SO link.
SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15
  • 1
    I believe this same feature is being requested here - https://github.com/Azure/azure-functions-eventgrid-extension/issues/92 It is not possible to get the delivery properties from the EventGrid trigger currently. – Josh Love May 04 '22 at 06:27