Also, check this topic Db database connection doesn't allow direct database connection
I dont know if aws works similar to others, but in some cases, you should give your ip on the trusted sources list, to allow the connection directly to your database like Cpanel uses “remote mysql”.
But, that is for direct database handling, not for creating apis on your site.