Amplify-cli: Mock error when trying to access GraphQL endpoint from Lambda

Created on 6 Nov 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

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
bug mock

Most helpful comment

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

"apinoriappGraphQLAPIIdOutput": "",
"apinoriappGraphQLAPIEndpointOutput": ""

All 4 comments

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

"apinoriappGraphQLAPIIdOutput": "",
"apinoriappGraphQLAPIEndpointOutput": ""

same issue https://github.com/aws-amplify/amplify-cli/issues/2453#issuecomment-561412658

edit - fixed with the workaround (for now)

We have released a fix for this as a part of v 4.18.0.

I'm still facing this issue, with the latest version of the CLI. Any workaround?

Was this page helpful?
0 / 5 - 0 ratings