Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amplify mock not setting API_*_GRAPHQLAPIENDPOINTOUTPUT env var correctly in lambda resolver #6548

Closed
hisham opened this issue Feb 4, 2021 · 6 comments
Labels
feature-request Request a new feature mock Issues tied to the mock functionality pending-release Code has been merged but pending release

Comments

@hisham
Copy link
Contributor

hisham commented Feb 4, 2021

Describe the bug
I have a graphql lambda resolver that as part of its processing does a create mutation via the same graphql API.

I am currently testing this lambda resolver via amplify mock. Everything works until the lambda attempts to do a graphql mutation.

The error I get is the following:

Lambda Data source failed with the following error

{
  type: 'Lambda:Unhandled',
  message: {
    message: 'Request failed with status code 403',
    name: 'Error',
    stack: 'Error: Request failed with status code 403\n' +
      '    at createError (/Users/hisham/src/ess-app/amplify/backend/function/EssGraphQLResolverFn/src/node_modules/axios/lib/core/createError.js:16:15)\n' +
      '    at settle (/Users/hisham/src/ess-app/amplify/backend/function/EssGraphQLResolverFn/src/node_modules/axios/lib/core/settle.js:17:12)\n' +
      '    at IncomingMessage.handleStreamEnd (/Users/hisham/src/ess-app/amplify/backend/function/EssGraphQLResolverFn/src/node_modules/axios/lib/adapters/http.js:260:11)\n' +
      '    at IncomingMessage.emit (events.js:327:22)\n' +
      '    at IncomingMessage.EventEmitter.emit (domain.js:467:12)\n' +
      '    at endReadableNT (internal/streams/readable.js:1327:12)\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:80:21)',
    config: {
      url: 'https://<myapi>.appsync-api.us-east-1.amazonaws.com/graphql',
      method: 'post',
      data: '{"query":"mutation....  

Looking at the url above, it is supposed to be http://192.168.86.25:20002 since I am running amplify mock, but instead it's my actual non-mock aws appsync endpoint. It does not appear that amplify mock sets the API...GRAPHQLAPIENDPOINTOUTPUT env var correctly.

Amplify CLI Version
4.41.2

To Reproduce
Create a lambda resolver that in turn calls the same graphql api with a mutation or query, and test via amplify mock.

@hisham hisham changed the title amplify mock not setting API_*_GRAPHQLAPIENDPOINTOUTPUT env var correctly in lambda amplify mock not setting API_*_GRAPHQLAPIENDPOINTOUTPUT env var correctly in lambda resolver Feb 4, 2021
@jhockett jhockett added mock Issues tied to the mock functionality bug Something isn't working labels Feb 4, 2021
@kaustavghosh06
Copy link
Contributor

@hisham So you have a Lambda resolver as a part of your schema which is calling the GraphQL endpoint as well?
Currently we don't set any environment variables locally for you - but you can set it locally as a process environment for local mocking purposes. We're working on a larger project for setting environment variables locally for lambda functions - cc @edwardfoyle

@kaustavghosh06 kaustavghosh06 added enhancement and removed bug Something isn't working labels Feb 5, 2021
@hisham
Copy link
Contributor Author

hisham commented Feb 5, 2021

Yes that's correct. Ok I'll try your suggestion next time I use amplify mock.

@hisham
Copy link
Contributor Author

hisham commented Feb 5, 2021

@kaustavghosh06 running the following does not work:

API_<myapi>_GRAPHQLAPIENDPOINTOUTPUT=http://localhost:20002 amplify mock

It seems the amplify mock code overrides it with the incorrect url.

I would have to set this env var in the lambda code instead, and then remove it when I do amplify push. Is there a way within lambda to know if it's in a mock environment? I see you set ENV to NONE and REGION to us-east-1-fake, and I can check other things in the env, but I wonder if there's an official way.

@kaustavghosh06
Copy link
Contributor

Got it. This would PR would potentially fix your issue @hisham - #6551

@edwardfoyle edwardfoyle added the pending-release Code has been merged but pending release label Feb 12, 2021
@edwardfoyle
Copy link
Contributor

A fix for this has been released in version 4.44.1 of the CLI. Please upgrade to the latest version to try it out.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
@josefaidt josefaidt added feature-request Request a new feature and removed enhancement labels Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature mock Issues tied to the mock functionality pending-release Code has been merged but pending release
Projects
None yet
Development

No branches or pull requests

5 participants