A function handler for query / mutation that is asynchronously invoked.
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())
https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#async-function-handlers
Use
async()
to have this function handler invoked asynchronously. If anasync()
function is only handler or the final handler in a pipeline, the return type of this custom query / mutation is{ success: boolean }
.