Back-end Engineering Articles

I write and talk about backend stuff like Ruby, Ruby On Rails, Databases, Testing, Architecture / Infrastructure / System Design, Cloud, DevOps, Backgroud Jobs, and more...

Twitter:
@daniel_moralesp

2020-04-10

Rails + AWS + ElasticBeanstalk & React + AWS + Amplify


## first important things
1- Create app with Ruby 2.6.7 ==> Because AWS takes this version ==> rvm use 2.6.7
2- When creating the app in ElasticBeanstalk dashboard I need to set
  - RAILS_ENV: production (don't confuse with RACK_ENV)
  - SECRET_KEY_BASE: aer152sdf... (choose the secret_key_base given by EDITOR="atom --wait" bin/rails credentials:edit)
    if this doens't work, I've to use the command `rake secret`, is different, and copy this in environments
3- Don't forget to change ENVs in database.yaml

## this is the tutorial that Im following: <https://dev.to/sname/deploy-rails-app-from-github-to-aws-4kk0>

It works! seems like the ENV vars are a pain in the but

## simple tutorial to allocate IPv4 to have this as a subdomain under app
<https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html>

## to access to ElasticBeanstalk and rails console and other commands in production, I need to install eb cli
<https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-advanced.html>
## connect EC2 environment with CLI
<https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-ssh.html>

## comands
eb ssh # add credentials
$ cd /var/app/current
$ bundle exec rails c
$ bundle exec rails db:seed
## other rails commands as normal

## react + amplify

# don't forget in local machine:
npm install
npm run-script build

Initial tutorial: <https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-one/>
Quite easy to follow, the only thing I had problem, was upgrade node-sass 
package to version 12, I saw the error in AWS logs. 

Then, aws create a personaliced subdomain, who I needed to change in order 
to point to my subdomain under front.datasource.ai
What I did here was:
1- Create under Route53 - aws service a hosted zone domain, under app.datasource.ai
2- Inside Amplify console, and under Domain management link, I followed this 
tutorial: <https://docs.aws.amazon.com/amplify/latest/userguide/to-add-a-custom-domain-managed-by-a-third-party-dns-provider.html>

Things Im trying to confirm neccesary:
1- Don't touch Namecheap
2- Inside Route53
  * create subdomain: app.datasource.ai
3- Once Route53 is created, change Amazon NS created for my cloudflare NSs:
      name1.ns.cloudflare.com
      name2.ns.cloudflare.com
4- Create Custom Domain under Amplify: <https://docs.aws.amazon.com/amplify/latest/userguide/to-add-a-custom-domain-managed-by-a-third-party-dns-provider.html>
5- Inside Cludflare validate and NS - Validation SSL under Cloudflare:
  * Type: CNAME
  * Name: _b328e6eb1434f70aa.app
  * Target: _f5993e240.vjldqjsdcd.acm-validations.aws (with -validation.aws extension)
  * Proxy Status: DNS Only
6- Once validation is ready, add other CNAMEs in Cloudflare. This CNAMEs are displayed
only when the SSL config inside Amplify is ready, and they give the instructions
  * Type: CNAME
  * Name: app
  * Target: targetname.cloudfront.net
  * Proxy Status: DNS Only
  ---------
  * Type: CNAME
  * Name: www.app
  * Target: targetname.cloudfront.net
  * Proxy Status: DNS Only
 7- Others
   * No needed to change build settings (default setup)
   * No needed to change Rewrites and redirects (default setup)

<https://stackoverflow.com/questions/61347633/configure-cloudflare-to-point-to-aws-amplify>

## Next tutorial
Next: <https://dev.to/mubbashir10/containerize-react-app-with-docker-for-production-572b>