First, getthe name of the distribution:
grep ^NAME /etc/*release
It will say something like “Amazon Linux” or “Amazon Linux AMI”.
sudo vim /etc/yum.repos.d/mongodb-org-4.2.repo
Then add this to the file:
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
Now, you can install MongoDB:
sudo yum install -y mongodb-org
Then, start MongoDB:
sudo systemctl start mongod
For additional info, check the official MongoDB documentation