Search code examples
aws-lambdaaws-amplifyaws-appsync

How to query AWS Lambda from Android app using AWS Amplify?


I have Android application where I need to trigger AWS Lambda. I'd like to use AWS Amplify since I'm already using it for communication with DynamoDB. I'm following documentation from:
https://docs.amplify.aws/cli/function#function-templates
https://docs.amplify.aws/cli/graphql-transformer/function


- I've created function via amplify console: amplify add function (function name: findOrderByProduct)

- I've added query in schema.graphql file as suggested in documentation:

type Query {
    findOrder(productIdentifier: String): String @function(name: "findOrderByProduct-${env}")
}


- I've pushed new resources to AWS: Lambda function and AWS AppSync Query has been created and class FindOrderQuery class has been generated.


- Now, I don't know how can I use generated classes, from Android app, to execute Lambda through AppSync query. Trying below:

Amplify.API.query(
                <what should go here? Should I use ModelQuery.get(...) or ModelQuery.list(...)? If yes, what arguments should I pass to get/list method?>,
                response -> {},
                error -> {}
        );

All help would be appreciated. Amplify documentation explains how to create lambda function very well but how to use it later (especially within Android libraries) isn't so obvious for me.
Regards


Solution

  • Follow this guide for Amplify Android's REST API category instead of the CLI @function docs.

    Amplify started as a JavaScript library. Over 2020 we had a few engineers build out some of the same functionality for Android, too. @function didn't make the cut, that's just for JS right now.

    Following the REST API guide, you'll end up with a system like this:

    (Phone) -> (Amazon API Gateway) -> (AWS Lambda)
    

    Source: I work on this team.