question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mock error when trying to access GraphQL endpoint from Lambda

See original GitHub issue

Describe the bug I want to access the GraphQL api from within a Lambda function to run queries and mutations in the backend.

My query for getting the next event is:

type Query {
  nextChatEvent(mainIntent: String): String @function(name: "nextChatEvent-${env}")
}

The lambda function should decide based on the users data (stored in a DynamoDB schema) what the next best event is for this user. As soon as I grant access to the function for using the api an error occurs when running $ amplify mock:

Failed to parse Lambda function cloudformation in app/amplify/backend/function/nextChatEvent/nextChatEvent-cloudformation-template.json

Error: Could not find ref for "apinoriappGraphQLAPIIdOutput"
Failed to start API Mock endpoint Error: Lambda function nextChatEvent does not exist in your project. 
Please run amplify add function

Amplify CLI Version 1.13.0

To Reproduce

  • create the model with the query
  • create a simple Lambda function called nextChatEvent
  • then run
$ amplify update function
Using service: Lambda, provided by: awscloudformation
? Please select the Lambda Function you would want to update nextChatEvent
? Do you want to update permissions granted to this Lambda function to perform on other resources in your project? Yes
? Select the category api
Api category has a resource called noriapp
? Select the operations you want to permit for noriapp create, read, update

You can access the following resource attributes as environment variables from your Lambda function
var environment = process.env.ENV
var region = process.env.REGION
var apiNoriappGraphQLAPIIdOutput = process.env.API_NORIAPP_GRAPHQLAPIIDOUTPUT
var apiNoriappGraphQLAPIEndpointOutput = process.env.API_NORIAPP_GRAPHQLAPIENDPOINTOUTPUT

? Do you want to edit the local lambda function now? No
Successfully updated resource

Expected behavior When I run the mock environment the error should not occur and from within the Lambda function I should be able to access the api like described in https://aws-amplify.github.io/docs/cli-toolchain/quickstart#graphql-from-lambda

Desktop (please complete the following information):

  • OS: OSX 10.13.6 (17G8030)
  • Node Version: v10.12.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
pattancommented, Nov 27, 2019

Have you tried to add this to your function-parameters.json

"apinoriappGraphQLAPIIdOutput": "",
"apinoriappGraphQLAPIEndpointOutput": ""
0reactions
github-actions[bot]commented, May 25, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Full Stack Error Handling with GraphQL and Apollo
If networkError is present in your response, it means your entire query was rejected, and therefore no data was returned. For example, the ......
Read more >
Developing and testing GraphQL APIs, Storage and Functions ...
The mock endpoint runs on localhost and simulates an AWS AppSync API connected to a DynamoDB table (defined at the GraphQL schema with...
Read more >
Is there an option to call mocked api inside mocked lambda ...
I want to use API inside one of my Lambda functions, so it has reference to ID and APIEndpoint [1] - the problem...
Read more >
Calling GraphQL API from a Lambda function - Amplify Docs
Choose the function template that you want to use: AppSync - GraphQL API request (with IAM) Available advanced settings: - Resource access permissions ......
Read more >
GraphQL | RedwoodJS Docs
Customizing the Error Message​. But what if you still want to share an error message with client? Simply use one of Redwood's GraphQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found