본문 바로가기

Azure Function Study

Azutre Functions triggers and bindings concepts

아래 마이크로 소프트 공식문서 내용을 찬찬히 읽으며 정리한 내용
Azure Functions triggers and bindings concepts
https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp)

functions triggers 와 bindings에 대해 공부하겠음.

Triggers

트리거는 Azure Function이 실행되도록 하는 역할을 한다
트리거는 Azure Function이 어떻게 invoke 되는지 정의함
하나의 Azure Function은 정확히 한개의 트리거만 가지고 있어야함
트리거는 데이터와 연관되어있는데, 주로 payload of the function으로 제공되는 데이터임
즉, payload, 의도된 메세지, json과 같이 약속된 큐 메세지와 같은 형식의 데이터를 말함.

payload https://en.wikipedia.org/wiki/Payload_(computing)
the part of transmitted data that is the actual intended message

Binding to function은 다른 리소스를 애저 함수에 연결하는 것을 선언하는 방법임
바인딩은 input binding 또는 output binding 혹은 둘다 같이 연결하여 사용할 수 있음
binding에서의 데이터는 애저함수의 파라미터로 제공받을수 있음

필요에 따라 다른 종류의 바인딩들을 섞거나 매치하여 사용 가능함, 바인딩은 옵셔널하고, 애저 함수는 한개 혹은 여러개의 인풋 혹은 아웃풋 바인딩을 가질수 있음

Example scenario Trigger Input binding Output binding
A new queue message arrives which runs a function to write to another queue. Queue_ None Queue_
A scheduled job reads Blob Storage contents and creates a new Cosmos DB document. Timer Blob Storage Cosmos DB
The Event Grid is used to read an image from Blob Storage and a document from Cosmos DB to send an email. Event Grid Blob Storage and Cosmos DB
A webhook that uses Microsoft Graph to update an Excel sheet. HTTP None Microsoft Graph

*Queue 두개는 각각 다른 큐를 나타냄

Trigger and binding definitions

Triggers와 bindings는 개발언어에 따라 다르게 정의됨

저는 파이썬 개발자이므로 파이썬 것만 첨부 :) function.json를 사용함
function.json의 스키마 http://json.schemastore.org/function

function.json과 관련해서는 다음 게시글에서 디테일하게 다룸 (https://pypypython.tistory.com/5)
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference?tabs=blob

 

Guidance for developing Azure Functions

Learn the Azure Functions concepts and techniques that you need to develop functions in Azure, across all programming languages and bindings.

docs.microsoft.com

function.json이 필요한 개발언어의 경우, 포탈이 UI로 bindings를 추가하는 Integration 탭을 제공함
portal에서 와 Azure Function의 code + test를 할수 있음
Visual Studio Code는 쉽게 binding을 function.json에 추가할수 있게해줌

편리한 도움 지침 셋 공유함

.Net과 자바는 필요 없음

Connect functions to Azure services using bindings 추후 게시글에서 다루겠음, 생성되면 링크 예정
https://docs.microsoft.com/en-us/azure/azure-functions/add-bindings-existing-function?tabs=csharp

 

Connect functions to other Azure services

Learn how to add bindings that connect to other Azure services to an existing function in your Azure Functions project.

docs.microsoft.com

자바스크립트 같이 dynamically하게 타이핑되는 언어는 dataType 프로퍼티를 function.json에 넣음.
예를 들어 바이너리 포맷의 HTTP request의 내용을 읽으려한다면, datasType은 binary로 주어야한다.
예시)

{
    "dataType": "binary", # dataType에는 "stream", "string"이 들어갈 수 있다.
    "type": "httpTrigger",
    "name": "req",
    "direction": "in"
}

Binding Direction

모든 트리거들과 바인딩들은 direction 프로퍼티를 가진다

  • 트리거들의 direction은 언제나 "in"
  • input과 output bindings은 "in" 과 "out"
  • 어떤 종류의 바인딩들은 특별한 direction인 "inout" 을 서포트한다. "inout"을 사용하려면, 포털의 Intergrate 탭의 Advanced editor에서만 사용 가능하다

Add bindings to a function

function을 다른 서비스들에 연결하고자 한다면 input 또는 output bindings를 사용해서 연결이 가능하다
bindings를 애저 function에 필요에 맞게 특정하게 정의하여 추가하라!

방법을 공유한다. 해당 내용은 추후 게시글에서 다루겠음, 생성되면 링크 예정
https://docs.microsoft.com/en-us/azure/azure-functions/add-bindings-existing-function?tabs=csharp

 

Connect functions to other Azure services

Learn how to add bindings that connect to other Azure services to an existing function in your Azure Functions project.

docs.microsoft.com

 

'Azure Function Study' 카테고리의 다른 글

Azure Functions developer guide > function.json  (0) 2022.08.05