Accessing Roblox Api Using Aws Lambda?

I’m really new to web developing and I’m currently working on making my game efficient by switching from Railway Roproxy Lite to Aws Lambda.

My problem is that I don’t know how coding in Aws Lambda works and most of the Wiki I find about it are irrelevant or I just don’t understand them.

Theres a huge difference between Railway Roproxy Lite and Aws Lambda.
Roproxy already have a backend to it so you only need to send requests from roblox.

Aws lambda on the other hand serverless computing platform.
Which language are you using?

Javascript - Node js?
or
Python?

1 Like

I’m using Node.JS since it looks easier than the other one

I’m not using Roproxy since I’m constantly requesting for the player’s data and would probably just break the system.

this is the script I wanted aws lambda to do

local modul = {}

local HTTPService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local getAsync = HTTPService.GetAsync
local jsonDecode = HTTPService.JSONDecode

local clothingUrl = ""
local gamepassesUrl = ""
local gamesUrl = ""


local function getClothing(targetId, targetType, cursor, clothing)
	cursor = cursor or ""
	clothing = clothing or {}

	local requestUrl = clothingUrl:format(targetId, targetType, cursor)
	local success, result = pcall(getAsync, HTTPService, requestUrl)
	if success then
		if result then
			local success2, result2 = pcall(jsonDecode, HTTPService, result)
			if success2 then
				if result2 then
					for _, clothingItem in ipairs(result2.data) do
						if not table.find(clothing, clothingItem.id) then
							table.insert(clothing, {clothingItem.id,clothingItem.price})
						end
					end

					cursor = result2.nextPageCursor
					if cursor then
						return getClothing(targetId, targetType, cursor, clothing)
					else
						return clothing
					end
				end
			else
				warn(result2)
				task.wait(1)
				return --getClothing(targetId, targetType, cursor, clothing)
			end
		end
	else
		warn(result)
		print("t")
		task.wait(1)
		return "bruh"--getClothing(targetId, targetType, cursor, clothing)
	end
end

local function getGamepassesRecursive(gameId, cursor, gamepasses)
	cursor = cursor or ""
	gamepasses = gamepasses or {}

	local requestUrl = gamepassesUrl:format(gameId, cursor)
	local success, result = pcall(getAsync, HTTPService, requestUrl)
	if success then
		if result then
			local success2, result2 = pcall(jsonDecode, HTTPService, result)
			if success2 then
				if result2 then
					for _, gamepassItem in ipairs(result2.data) do
						if table.find(gamepasses, gamepassItem.id) == nil and gamepassItem.price ~= nil then
							table.insert(gamepasses, {gamepassItem.id,gamepassItem.price})
						end
					end

					cursor = result2.nextPageCursor
					if cursor then
						return getGamepassesRecursive(gameId, cursor, gamepasses)
					else
						return gamepasses
					end
				end
			else
				warn(result2)
				task.wait(1)
				return --getGamepassesRecursive(gameId, cursor, gamepasses)
			end
		end
	else
		warn(result)
		print("t")
		task.wait(1)
		return --getGamepassesRecursive(gameId, cursor, gamepasses)
	end
end

		
local function getGames(targetId, targetType, cursor, games)
	cursor = cursor or ""
	games = games or {}

	local requestUrl = gamesUrl:format(targetType, targetId, cursor)
	local success, result = pcall(getAsync, HTTPService, requestUrl)

	if success then
		if result then
			local success2, result2 = pcall(jsonDecode, HTTPService, result)
			if success2 then
				if result2 then
					for _, gameItem in ipairs(result2.data) do
						table.insert(games, gameItem.id)
					end 

					cursor = result2.nextPageCursor
					if cursor then
						return getGames(targetId, targetType, cursor, games)
					else
						return games
					end
				end
			else
				warn(result2)
				task.wait(1)
				return --getGames(targetId, targetType, cursor, games)
			end
		end
	else
		warn(result)
		print("yes")
		task.wait(1)
		return nil --getGames(targetId, targetType, cursor, games)
	end
end	

function modul.GetProducts(userId)
	local sellableAssets = {}	
	local userClothing = getClothing(userId, 1)
	local userGames = getGames(userId, "users")
	local userGamepasses = {}
	
	if userClothing == "bruh" then
		print("ta")
		return "bruh",nil
	end --- if error
	


	for _, userGameId in ipairs(userGames) do
		local userGameGamepasses = getGamepassesRecursive(userGameId)
		for _, userGameGamepass in ipairs(userGameGamepasses) do
			table.insert(userGamepasses, userGameGamepass)
		end
	end

	for _, userClothingId in ipairs(userClothing) do
		table.insert(sellableAssets, userClothingId)
	end
	
	print(sellableAssets, userGamepasses)
	return sellableAssets, userGamepasses
end


return modul
1 Like

You can get the api that you’ve been looking from below:

Now you need to fetch them
So install node-fetch

If its not an ES6 module then install it to version 2

npm i node-fetch@2

other wise use the latest version

npm i node-fetch@latest

(Learn more about ES6 modules here)

If you’ve installed it by using first method then do

// backend
const fetch = require("node-fetch")

async function fetchIt(){
   let response = await fetch("roblox-api-url")
   return response
}

console.log(fetchIt())

If you are using 2nd method

// backend
import fetch from "node-fetch"

async function fetchIt(){
   let response = await fetch("roblox-api-url")
   return response
}

console.log(fetchIt())

When you are done with the code, create an API then put that api url in your script.

Heres the -10 minutes video tutorial on youtube (since i am lazy)

1 Like

According to the article HttpService
You only can send 500 requests per minute.

(This means you only can use HttpService:GetAsync(...) only 500 times per minute)

1 Like

How do I import Node Fetch to my code source?

1 Like

Simply use in your terminal

npm i node-fetch@2

After that import it by doing

const fetch = require('node-fetch')
// Your other code here
1 Like

Like this?

image

Also, it shows this whenever I use the api gateway thing
image

1 Like

Check your console, this might be the error because you are using import outside a module.

Replace that import with

const fetch = require('node-fetch')
// Your other code here

As mentioned above.

I pressed the test button and this is what it shows

Response
{
  "errorType": "Runtime.HandlerNotFound",
  "errorMessage": "index.handler is undefined or not exported",
  "trace": [
    "Runtime.HandlerNotFound: index.handler is undefined or not exported",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:246:11)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
    "    at Module.load (internal/modules/cjs/loader.js:950:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
    "    at internal/main/run_main_module.js:17:47"
  ]
}

Theres somthing wrong with your zipping.
You can try the solutions at this stackoverflow question:

https://stackoverflow.com/questions/60665901/index-handler-is-undefined-or-not-exported

Okay so, I really can’t find any really basic instructions on how I could make something on Lambda similar to Roproxy Lite so I’m just gonna stick with the Railway for now until the playerbase is big