AppSync pass querystring/variables to authentication lambda for subscription request

1

We are using AppSync with Lambda authentication. I front-end, we are using Amplify package. For each subscription request, we want to authenticate the user by checking if the current user has permission to subscribe to the given channel. Currently, the queryString and variables are not passed to lambda function for a subscription request. How can we handle this?

  • We're having the same issue with lambda auth. Intermittently (more often it fails than succeeds) the query string and variables for subscriptions are not sent. We still receive the authorizationToken but without the query string and variables we cannot validate the request.

    Queries and mutations are always successful but subscriptions are random. Sometimes they work and sometimes they don't without changing anything.

asked 10 months ago247 views
2 Answers
0

After some troubleshooting, I'm nearly certain this results from AppSync sending the connection init message to the authorizer. This message doesn't contain the query or the variables. The start subscription message will include them. So if you do not allow the init to go through, neither will the variables or query.

This presents other problems with lambda auth caching in AppSync because the token is already authorized and cached without actually validating the values from the query.

answered 8 months ago
-2

You could check the “Lambda Proxy Integration” in API Gateway, ensure your Lambda function has correct permissions.

profile picture
EXPERT
answered 10 months ago
  • We are not using API gateway here. AppSync is calling the lambda function to authenticate the request. For mutation and query request, the data is properly going. Only for subscription request, the data is not going.

  • I'm facing the same issue - a request going through a custom authorizer Lambda does not include queryString and variables in the payload.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions