Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

354
Visualizações
How do you import a custom lambda function in Amplify React component?

CURRENTLY

I have created an amplify app with react, and have a component src > components > MyReactComponent.js with a button that when pressed I would like to get data from an external API (that requires auth), and retrieve back to the react component.

The workflow I was building is as follows:

enter image description here

I created a Lambda function in Amplify CLI using amplify add function. This created a function getExternalData in my project structure as follows:

-- amplify
| -- backend
|   -- api/
|   -- auth/
|   -- function
|     -- getExternalData   <--- newly created function
|       -- dist/
|       -- src
|       | -- event.json
|       | -- index.js
|       | -- package-lock.json
|       | -- package.json
|       -- getExternalData-cloudformation-template.json
-- src
  -- components
  | -- MyReactComponent.js
  -- graphql
    -- mutations.js
    -- queries.js
    -- subscriptions.js
    -- schema.json

ISSUE

How do I import this function into MyReactComponent.js?

The dirtiest but most direct (and incorrect) method I could think of was:

import { getExternalData } from "../../amplify/backend/function/getExternalData/getExternalData";

But this returned the error:

Module not found: You attempted to import ../../amplify/backend/function/getExternalData/getExternalDatawhich falls outside of the project src/ directory. Relative imports outside of src/ are not supported.

I feel like ideally I would want the function to be available under graphql folder, but not sure how to automate it being listed there.

REQUEST

Any help to either:

  1. Help me import the Lambda function into MyReactComponent.js, or
  2. Suggest a better solution for securely getting the external data into react,

would be greatly appreciated :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda