I am trying to create Postgres user, passWord and database using userdata field in AWS EC2.
My last attempt was:
sudo su postgres
psql -U postgres -c "CREATE ROLE postgre;"
psql -U postgres -c "ALTER ROLE postgre WITH LOGIN;"
psql -U postgres -c "ALTER USER postgre CREATEDB;"
psql -U postgres -c "ALTER USER postgre WITH ENCRYPTED PASSWORD '1234567';"
psql -U postgres -c "create database productdb';"
I got this error message for each 5 last lines above:
psql: error: FATAL: Peer authentication failed for user "postgres"
Any suggestion to create user, password and database using userdata field in EC2?
I found this link, but I dont know how use this solution in EC2 userdata script.