• Time: 30-45 min
  • Level: Intermediate
  • Code: Application
  • Revision: May 14, 25

TL;DR

Check README

IMPORTANT: Don’t forget to delete resources with npm run cdk destroy Prototype

  1. Create AWS account
  2. git clone git@github.com:bpohoriletz/prototype.git (clone repo from GitHub)
  3. git checkout -b codedeploy (switch to codedeploy branch)
  4. make check (verify you have all dependencies)
  5. make install (install node packages)
  6. make bootstrap (prepare AWS for deployment)
  7. cd cloud && npm run cdk deploy Prototype (create infrastructure in AWS)
  8. cd .. (navigate to folder with project)
  9. bin/upload (upload project files to S3 bucket)
  10. bin/deploy <revision_path_from_previous_command> (deploy to EC2 in an autoscaling group)

As deployment completes you should have an EC2 server running your code, you can find the URL in the instance propss. url Ignore the certificate warning - the certificate is generated by the deployment and self-signed. Go to Section V - Fix 500 for instructions how to fix 500 error. ssl-error

Section I - Intro

Have you ever struggled with deployment to the cloud? Many developers (including me) did!

Few years ago I had an idea - implement the prototype, that I could use whenever I would like to explore the new idea. Since I like to explore ideas by implementing them I built this repo. I added authentication with Devise, styling with Tailwind, checks with Guard. However when I was ready to to test production setup I had no idea where to start, some guys on my team deployed projects with Capistrano, and that was basically all knowledge I had.

That situation has changed, today my prototype includes infrastructure component, deployment works, hey it works ony my Mac :)

This post will be only a high-level description of the components, in later posts I will review each part in detail.

So lets dive in!

Section II - Environment

You can verify if your environment is ready with make check. Output should look like

Verifying Node.js .... yes v22.12.0
Verifying AWS CLI .... yes aws-cli/2.25.8 Python/3.12.9 Darwin/24.4.0 source/arm64
Verifying AWS credentials set for 'my' profile.
executing aws sts get-caller-identity --profile=my .... got Account: 400000000000
 ********* All Set! ***********

For settig up AWS credentials please refer to the following guides:

  1. AWS CLI - HOWTO
  2. AWS Account - HOWTO

In the end you should have profile [my] like in example file

Section III - Cloud

Next you need to create infrastructure in AWS where you’ll later deploy prototype app.

In order to do so install dependencies with make install and prepare resources in AWS with make bootstrap. Now your local environment is all set to create infrastructure.

First you neeed to navgate to the cloud folder. Now you can review resources with npm run cdk diff Prototype. When ready deploy with npm run cdk deploy Prototype, afrter succesful deployment you should see something like

Do you wish to deploy these changes (y/n)? y
Prototype: deploying... [1/1]
Prototype: creating CloudFormation changeset...

 ✅  Prototype

✨  Deployment time: 228.45s

Stack ARN:
arn:aws:cloudformation:us-east-2:400000000000:stack/Prototype/2e5b88e0-3090-11f0-8b5f-0213dd2454d5

✨  Total time: 240.58s

Section IV - Deployment

Deployment of the project includes two steps: upload zipped files to S3, create CodeDeploy deployment.

To upload zipped files to S3 run bin/upload. In the end you should see where files were uploaded.

Compressing: vendor/javascript
Compressing: vendor/javascript/.keep


File uploaded successfully.
Path: codedeploy-rails-prototype-us-east-2-400000000000-bct/resources/versions/63278a4.zip

Copy the path above for the next step.

To deploy S3 version to EC2 run bin/deploy <path_from_the_deploy_step>. In the end you should see deployment id

prototype ❯ bin/deploy codedeploy-rails-prototype-us-east-2-400000000000-bct/resources/versions/63278a4.zip
Deploying resources/versions/63278a4.zip to rails-prototype-dg of rails-prototype-cd-app from codedeploy-rails-prototype-us-east-2-400000000000-bct
Application revision registered with CodeDeploy.
Deployment started with ID: d-ONVA2F4IB

deployment

Section V - Fix 500

While this could be done automatically I decided to create this section to give you an opportunity to manually run commands on the EC2.

If you now navigate to the EC2 url you will see the 500 eror page, fixing error is the last step. 500.html

First you need to connect to EC2, this is done with SessionManager. ec2-connect

Now you can check the error with sudo journalctl -u web

a3e] Started GET "/" for 92.253.212.68 at 2025-05-14 07:20:02 +0000
]: [73e17295-0649-42e2-baa1-147f8a34da3e] Processing by DashboardController#index as HTML
]: [73e17295-0649-42e2-baa1-147f8a34da3e] Completed 401 Unauthorized in 36ms (ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)
]: [cab324ed-1b22-45e5-b35f-5fed81ef365d] Started GET "/accounts/sign_in" for 92.253.212.68 at 2025-05-14 07:20:02 +0000
]: [cab324ed-1b22-45e5-b35f-5fed81ef365d] Processing by Devise::SessionsController#new as HTML
]: [cab324ed-1b22-45e5-b35f-5fed81ef365d] Completed 500 Internal Server Error in 17ms (ActiveRecord: 1.7ms (0 queries, 0 cached) | GC: 0.0>
]: [cab324ed-1b22-45e5-b35f-5fed81ef365d]
]: [cab324ed-1b22-45e5-b35f-5fed81ef365d] ActiveRecord::StatementInvalid (Could not find table 'accounts'):

Missing table, oh migrations, fixed it before :/

bash
sudo su - ec2-user
cd /var/app/current
RAILS_ENV=production bin/rails db:migrate

Finally final

Summary

IMPORTANT: Don’t forget to delete resources with npm run cdk destroy Prototype

While this tutorial is about AWS, many if not all cloud providers have API, which may be used to provision infrastructure and deploy applications. What I hope you will take from this tutorial, as from many other tails, dragons exist, but they can be killed! Few years ago cloud was scarry, these days I have some dragon heads on my wall.

Self-promotion

This post is only high-level guide, there is plenty of stuff under the surface which I will disclose in later parts. However if you happen to be in Cologne this June, you can find me at SREday Cologne 2025 Q2

Revisions

  • May 15, 25 - Initial post