🦐 🍤 🦐 🍤 🦐 🍤 🦐 🍤 🦐 🍤 🦐 🍤
A modern page view counter to see how unpopular my project is. Powered by a PRAwN stack (Postgres, React, AWs and Node) in the free tier, deployed using CDK.
- Postgres.
- React.
- Aws.
- Node.
We're also using Typescript and NextJS for the frontend.
docker-compose up --build
starts postgres, the node api development server and the nextjs development server.npm run start
run the development Node server.npm run dev
run the NextJS development server.npm run test
perform the jest unit tests.npm run build
build the NextJS frontend so it's ready to deploy.npx aws-cdk bootstrap --profile account-name
prepare the AWS region for cdk deployments.npm run deploy -- --profile account-name
build the frontend and deploy the cdk stack.npx aws-cdk destroy --profile account-name
destroy the deployment.
- Install dependencies.
npm install
- Run docker-compose.
This will bring up:
docker-compose up --build
- Postgres database and run migrations on it using Flyway.
- PgAdmin to access the Postgres database. Available at http://localhost:5050/.
- Node API development server. Available at http://localhost:3001/api/.
- NextJS development server for the frontend. Available at [http://localhost:3000](http://localhost:3000.
Going forward, you can make this faster by skipping the build step. You only need it if your dependencies change.
docker-compose up
- Go to http://localhost:5050/.
- Set a master password.
- Click Add New Server.
- Fill in the local server details.
- General
- Name: local
- Connection
- Host: postgres
- Username: postgres
- Password: changeme
- Save password?: yes
- General
Make sure you setup email forwarding for admin
@yourdomain (e.g admin@cadell.dev
) you receive the email from aws to validate that you own the domain so it can create a certificate.
- Create an AWS account.
- Click Signin.
- Click Create a new AWS account.
- Enter your details.
- Go to IAM.
- Enable MFA on your Root account. I recommend 1Password.
- Create an IAM user without console access, assign the AdministratorAccess permission and setup an access key.
- Download the credentials.
- Create a
.aws
folder if you don't already have one.mkdir ~/.aws
- Create a credential file with
vi ~/.aws/credentials
.[{account-name}] aws_access_key_id={access_key} aws_secret_access_key={secret_key}
- Run
npm install
to install dependencies. - Run
npm run build
to build the project. - Set the region in
bin/prawn-cdk.ts
. - Update
yourPublicIpAddress
inbin/prawn-cdk.ts
with your public ip address so you can access the database. - Run
npx aws-cdk bootstrap --profile {account-name}
. - Run
npx aws-cdk deploy CertificateStack --profile {account-name}
.- This will send an email to
admin@yourdomain
to confirm you control the domain for the certificate it's creating. You can also go into CertificateManager inus-east-1
region and resend it if you need to. - The command won't finish until you approve the email.
- This will send an email to
- Copy the certificateArn from the output and add it to the
bin/prawn-cdk.ts
. - Run
npm run deploy -- --profile account-name
.- This takes about about 15 mins.
This takes about 1-3 mins.
npm run deploy --profile account-name
You'll need to do this to setup the database initially.
Access is currently through a whitelisted ip address which isn't ideal but will work well enough for now.
- Make sure the
yourPublicIpAddress
inlib/prawn-stack.ts
is up to date and deployed. - Login to the AWS console.
- Go to Secrets Manager.
- Select the region, probably
ap-southeast-2
. - Click
PrawnStack-rds-credentials
. - Go to the
Secret value
section then clickRetrieve secret value
.
You can put the values into PgAdmin to query the database.
- Make sure Docker is running.
- Run flyway migrate with connection details and credentials from secrets manager.
HOST=xxx USER=xxx PASSWORD=xxx; docker-compose run flyway -url=jdbc:postgresql://$HOST/postgres -user=$USER -password=$PASSWORD migrate
- Sign into your domain registrar. I use Google Domains.
- Setup a new CNAME DNS record using the cloudfront domain in the deploy output.
- Make sure the CNAME aligns with the
customDomain
inbin/prawn-cdk.ts
.
npx aws-cdk destroy --profile account-name
- Login to the root account.
- On the account dropdown on the top right, click My Billing Dashboard.
- Click Cost Explorer.
- Click Daily Spend View.
- Change the timeframe to the last 7 days.
- Group by Usage Type.
The table below will give you a decent breakdown on your charges.