-
log into aws console https://console.aws.amazon.com/
-
go to aws cloud 9 https://console.aws.amazon.com/cloud9/
-
create new environment (use all defaults)
-
Copy and paste each command (one at a time) in the console which is provided
sudo -i
yum install postgresql15-server -y && service postgresql initdb && service postgresql start
- sometimes this command hangs and you'll see an error about a lock and yum. This usuallly resolves by waiting, or you can always do ctl-c to kill the command and try again. Sometimes it takes a few times.
sudo -u postgres psql
create user "ec2-user" createdb; create database "ec2-user";
\q
rm -f /var/lib/pgsql/data/pg_hba.conf && echo "local all all trust">>/var/lib/pgsql/data/pg_hba.conf && echo "host all ec2-user all trust">>/var/lib/pgsql/data/pg_hba.conf
service postgresql restart && exit
NOTE: your environment will terminate when not in use, so when you log back in you probably want to start postgres
sudo -i
service postgresql start && exit
Don't use this environment to store applications. If something is important, push it up to github. If it's not important, delete it. Plus it doesn't take much to setup a new environment.
hit enter for defaults
ssh-keygen -t ed25519 -C <your email surrounded by double quotes>
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
- copy contents of file (example below)
ssh-ed25519 some-long string etccc.. youremail@email.com
- create .ssh key with this value on github.com
https://github.com/settings/ssh/new
git config --global user.name "FIRST_NAME LAST_NAME"
createdb acme_db && mkdir app && cd $_ && npm init -y && npm i pg express && touch server.js
const pg = require('pg');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const client = new pg.Client('postgres://localhost/acme_db');
client.connect();
client.query(`
DROP TABLE IF EXISTS users;
CREATE TABLE users(
name VARCHAR(255)
);
`)
.then(()=> {
return Promise.all([
client.query('insert into users(name) values($1)', ['moe']),
client.query('insert into users(name) values($1)', ['lucy'])
]);
})
.then(()=> {
app.listen(port, ()=> console.log(`listening on port ${port}`));
});
app.get('/', (req, res, next)=> {
client.query('select * from users;')
.then( response => res.send(response.rows))
.catch(next);
});
node server.js
- click preview application button
- you should see an api call to your application which shows users
- take app you created in previous steps
- create a local github repo
- create a repo on github
- push local github repo to github
- when pushing for first time you will be prompted about using new key, hit enter (default)
- any code you create you can push to github where you can always access it
- you can delete your cloud 9 environment anytime you want and always recreate it!