#✅ - How to trigger lambda in custom pipeline resolver

6 messages · Page 1 of 1 (latest)

lavish heron
#

I have a function that is added to amplify data like this:

export const data = defineData({
  schema,
  functions: {
    "function-send-sms": sendSMSFunction,
  },
  authorizationModes: {
    defaultAuthorizationMode: "apiKey",
    apiKeyAuthorizationMode: {
      expiresInDays: 30,
    },
  },
});

I want to trigger this function in my custom pipeline resolver like this:

    .handler([
      a.handler.custom({
        dataSource: "function-send-sms",
        entry: "./resolver/send-sms.js",
      }),
      a.handler.custom({
        dataSource: a.ref("DoSomeOtherThings"),
        entry: "./resolver/do-some-other-things.js",
      }),
    ])

It says that data source "function-send-sms" is not found. Do you know how to fix this? Thank you very much.

This is the error log message:

Resource handler returned message: "No data source found named function-send-sms (Service: AppSync, Status Code: 404,
lavish heron
#

In many pages on the Internet, I often see instruction like this "Create an AWS AppSync API, and then attach the Lambda function as the data source."

But I don't know how exactly I can do this in amplify/data/resource.ts

#

I've figured it out, I have to to this in backend.ts:

const backend = defineBackend({
  auth,
  data,
  sendSMSFunction,
});

backend.data.addLambdaDataSource("sendSMSFunction", backend.sendSMSFunction.resources.lambda);

It would be nice if this is written somewhere in documentation, it would save me a lot of time.

celest kiln
#

@lavish heron, glad you were able to unblock yourself! Is there a specific page in the docs (either on the functions section or elsewhere) that you think this would have been most helpful in?

ember plinthBOT
#

✅ - How to trigger lambda in custom pipeline resolver