Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!