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
nextChatEvent$ 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):
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?
Most helpful comment
Have you tried to add this to your function-parameters.json