Depending on where you are hosting the database, the connection details would change accordingly:
- Hosting Database yourself on the server itself (not recomended): If your database instance lies on the same server then your code should work as it is. This is because the
host will still be localhost and you have configured the credentials appropriately. In cloud enviornment this is not recomended for various reasons - if your instance goes down, the database goes down as well and more importantly you will have to manage the database which includes things like backups, mirroring, scaling etc
- Use Amazon Relational Database service - RDS (recomended): Depending on the type of security you want to implement, you can take any one of the routes mentioned here. Essentially you use the endpoint of the RDS instance as the
host. As for authentication, you can go the normal route of configuring username and password when configuring the instance.
RDS is the recomended way to go as being a managed service, you offload a lot of heavy lifting that comes with managing a database to AWS.
If you are starting out, RDs also Free Tier bundle (link)
Note: While provisioning the RDS instance or whike updating it, be sure to mark the option of "Enable Internet Access". This will make it possible for you to access the database via the internet eg outside the VPC, from your home etc