FunctionHandler: {
    [brandSymbol]: typeof functionHandlerBrand;
    [dataSymbol]: FunctionHandlerData;
    async(): AsyncFunctionHandler;
}

Type declaration

  • [brandSymbol]: typeof functionHandlerBrand
  • [dataSymbol]: FunctionHandlerData
  • async:function
    • Use async() to have this function handler invoked asynchronously. If an async() function is only handler or the final handler in a pipeline, the return type of this custom query / mutation is { success: boolean }.

      Returns AsyncFunctionHandler

      A function handler for query / mutation that is asynchronously invoked.

      Example

      import {
      type ClientSchema,
      a,
      defineData,
      defineFunction // 1.Import "defineFunction" to create new functions
      } from '@aws-amplify/backend';

      // 2. define a function
      const echoHandler = defineFunction({
      entry: './echo-handler/handler.ts'
      })

      const schema = a.schema({
      EchoResponse: a.customType({
      content: a.string(),
      executionDuration: a.float()
      }),

      echo: a
      .query()
      .arguments({ content: a.string() })
      .returns(a.ref('EchoResponse'))
      .authorization(allow => [allow.publicApiKey()])
      // 3. set the function has the handler
      .handler(a.handler.function(echoHandler).async())

      See

      https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#async-function-handlers