aws amplify: calling a 3rd party api within a endpoint handler blocks without any return

14 Views Asked by At

i am new to aws amplify and want to implement some backend logic to call 3rd party apis within a endpoint handler. my calls to 3rd party apis always get blocked.

to test this issue, i wrote the a nextjs 14.1.4 test app. i wrote the simplest handler within "pages/api/test.js" endpoint with a call to a 3rd party api "google.com". the code is shown as below:

// write code for a most simple get endpoint that returns "Hello Amplify"
export default async (req, res) => {
    res.status(200).json({ text: 'Hello Amplify' })

    console.log(
        "Making outbound api calls to https://www.google.com ..."
    );
    const response = await fetch("https://www.google.com/");
    const data = await response.text();
    console.log("Data from the simpliest api call: ", data);
}

when i deploy it on aws amplify and call the endpoint from chrome browser, the call to google api blocks without any return. the amplify logs is listed below:


2024-03-21T22:15:07.553+08:00   INIT_START Runtime Version: nodejs:18.v24 Runtime Version ARN: arn:aws:lambda:us-east-2::runtime:c09960ad0af4321e1a7cf013174f7c0d7169bf09af823ca2ad2f93c72ade708a

2024-03-21T22:15:07.600+08:00   LOGS Name: bootstrap State: Subscribed Types: [Platform, Function]

2024-03-21T22:15:08.170+08:00   START RequestId: 7d6f1c0b-d568-4a95-8e11-ee52a7c731a7 Version: $LATEST

2024-03-21T22:15:08.173+08:00   ▲ Next.js 14.1.4

2024-03-21T22:15:08.173+08:00   - Local: http://localhost:3000

2024-03-21T22:15:08.173+08:00   - Network: http://127.0.0.1:3000

2024-03-21T22:15:08.573+08:00   ✓ Ready in 446ms

2024-03-21T22:15:08.730+08:00   REPORT RequestId: 7d6f1c0b-d568-4a95-8e11-ee52a7c731a7 Duration: 560.33 ms Billed Duration: 561 ms Memory Size: 1024 MB Max Memory Used: 131 MB Init Duration: 616.00 ms

2024-03-21T22:15:11.349+08:00   START RequestId: 4237cde9-60b9-49d6-a9f4-00e78d7d26a2 Version: $LATEST

2024-03-21T22:15:11.388+08:00   REPORT RequestId: 4237cde9-60b9-49d6-a9f4-00e78d7d26a2 Duration: 39.66 ms Billed Duration: 40 ms Memory Size: 1024 MB Max Memory Used: 132 MB

2024-03-21T22:15:16.120+08:00   START RequestId: f56d4ea3-57e8-416b-84f2-813205d50684 Version: $LATEST

2024-03-21T22:15:16.156+08:00   Making outbound api calls to https://www.google.com ...

2024-03-21T22:15:16.166+08:00   REPORT RequestId: f56d4ea3-57e8-416b-84f2-813205d50684 Duration: 45.99 ms Billed Duration: 46 ms Memory Size: 1024 MB Max Memory U

could anyone give some clue where went wrong? why calls to 3rd party apis are always blocked? i check my aws amplify network configuration. things are default and seems outbounds traffics are allows.

pls help!

i did the above testing program and expect fellow programmers give me some clue to fix it. thanks a lot!

0

There are 0 best solutions below