Smart contract 404 error when running on AWS

I am building my smart contract on Amazon AWS. The error of 404 appears for several times when I am trying to opt in accounts into smart contract.

Any ideas on this kind of error?

404’s happen with the API when the thing you are looking for isn’t found. The last line refers to a transaction, and it appears that for whatever reason, the ID you are requesting isn’t present.

This could be because the transaction wasn’t submitted or wasn’t accepted when it was submitted.

Thanks for your reply @Tim

I am curious about the reason why opt-in actions are so unstable when running in AWS. I have run the same code in my personal computer, and seldom did this kind of error occur.

To run the code on AWS smoothly, do you have any advice?

What may happen is that you are not querying the same node than the one you used to post the transaction (e.g., the algod endpoint you are using is actually a load balancer and there are many algod nodes behind).
In that case, the node you are querying did not yet see the transaction.
Best is to wait for next block and try querying again.

Please also check you are using the v2 API (not the V1).
In the V2 API, the pending transaction endpoint will return the transaction up to 1,000 rounds after the transaction is indeed committed.
See code go-algorand/node.go at a3aa2fbacd332bd3f68fe835dc3392ba363757ea · algorand/go-algorand · GitHub

Thanks for your reply @fabrice .

I think I use the V2 API in my code, and as you can see in the screenshot, the transaction is not commited in 1000 rounds. I guess the problem here is the unstable connection between the server and AWS.

Is there any suggestions on how to fix that kind of problem? Or, some advice on how to avoid the throwing out error by HTTP requests not found?

Did you try to catch the error (in code), and if it is 404, wait for the next block, and try again?
Do you still have the error after doing that?
Can you show me the code you are using?