Rate Limited in Lambda

I am rate limited making a request from an AWS Lambda function.

The first request works, then the next one fails and is throttled via status code 429.

I can make the same request locally without any issue.

This is the endpoint in question:
https://api.opensea.io/api/v2/metadata/matic/{SMART_CONTRACT_ADDRESS}/{TOKEN_ID}

EDIT (above url is incorrect):
https://deep-index.moralis.io/api/v2/nft/0x2953399124F0cBB46d2CbACD8A89cF0599974963/{TOKEN_ID}/owners?chain=polygon&format=decimal"

Why is this request being throttled?

Here is a possible issue that could cause it:
Is it possible this has something to do with the request being made from an AWS IP?

EDIT:
I do not think AWS IP is the issue. This endpoint seems to be failing specifically when used with the OpenSea Store MATIC smart contract address: 0x2953399124f0cbb46d2cbacd8a89cf0599974963

We can not help with the opensea api. We don’t know how they implemented the rate limit. You could try to use a proxy for that request so that it doesn’t look like is made from aws. You can test it with ngrok and a local server on your computer that makes the request to opensea.

Oops, I copied the incorrect URL,

This is a Moralis API issue that only occurs with the smart contract address:
0x2953399124f0cbb46d2cbacd8a89cf0599974963 (this happens to be the OpenSea MATIC smart contract although has nothing to do with the OpenSea API).

and specifically with this endpoint, called from AWS Lambda:
https://deep-index.moralis.io/api/v2/nft/0x2953399124F0cBB46d2CbACD8A89cF0599974963/{TOKEN_ID}/owners?chain=polygon&format=decimal

In this case it shouldn’t matter if the request is made from aws or from a local IP. You are using the same api key? Is there a delay between requests?

It shouldn’t matter, although it is an issue.

When I make this API call locally, with the same API key as Lambda, it works locally when I run the function repeatedly, although not when run in Lambda repeatedly, failing after the first attempt. It works again at some random time later (~5-15 mins) when I try it again. Only with that particular smart contract address.

Do you have logging to see how many times the api endpoint is called?

Yes, I have logging.

What the logging shows is when run in AWS Lambda, for that Moralis endpoint, for that smart contract address only, the first request works, then subsequent requests do not for some time period, only for that smart contract address. Only when run from AWS Lambda.

Strange, any other contract works without issues?

Yes strange, although it seems to be the case.

And yes, other smart contracts work without issue.

One guess:
Maybe certain IP addresses + smart contract lookups are blocked somewhere unintentionally by an anti-spam bot or some firewall because that is a shared-use smart contract that I’m guessing many would be querying.

Hi @cryptokid,

This is still an issue and it is still occurring.
Can someone please look into this?

Do I have to go Karen mode and ask for the manager?

I don’t know what happens, I don’t know exactly what to check.

can you try to use a local proxy with ngrok to see if that way it works without issues?

you make the requests from a lambda function to another server that is hosted locally and proxied with ngrok and in the local server you make the requests to web3api, this ways you can see exactly what requests you make and in theory you should not get rate a rate limit error

Yes, that’s one way to check, proxy the request to Moralis by making it from another server (i.e. not Lambda), that way it can rule out if the Lambda environment/IP address is what’s causing the issue.

I’ll implement that when I can and I’ll get back to you.:+1:

1 Like