I need help calling an API form a URL and pulling that data to my S3 bucket

0

Hello, I am having trouble calling an API using Lambda trigger to collect data from this URL: https://data.nasdaq.com/api/v3/datatables/ZILLOW/DATA?indicator_id=ZSFH&region_id=99999&api_key=__afpDhxkYvt5XZzfEB- I wasnt sure what the best way to approach this was but I believe it can all be done through a lambda function? Also is there a certain way to word this process? I was looking for information about it online, but all I could find was tutorials of using the API Gateway which is not the approach that I am looking for thank you!

已提問 1 年前檢視次數 343 次
1 個回答
0

Hi,

it should definitely possible, without involving an API Gateway.

Make sure Lambda is either non in a VPC 8as it gets outbound internet traffic automatically), or if it is in VPC, then you will need a NAT Gateway + Internet Gateway (IGW).

Nevertheless, depending on your language of choice, you can use libraries such as native https or axios for NodeJS one or requests (https://pypi.org/project/requests/) for Python.

An example for Node:

const axios = require('axios');

exports.handler = async (event) => {
    const url = 'https://data.nasdaq.com/api/v3/datatables/ZILLOW/DATA?indicator_id=ZSFH&region_id=99999&api_key=__afpDhxkYvt5XZzfEB-';
    const response = await axios.get(url);
    const data = response.data;
    return data;
};

or for Python:

import requests

def lambda_handler(event, context):
    url = 'https://data.nasdaq.com/api/v3/datatables/ZILLOW/DATA?indicator_id=ZSFH&region_id=99999&api_key=__afpDhxkYvt5XZzfEB-';
    response = requests.get(url)
    data = response.json()
    return data

Hope it helps ;)

profile picture
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南