zodern / mup-aws-beanstalk

Deploy Meteor apps to AWS Elastic Beanstalk using Meteor Up
127 stars 55 forks source link

Is it possible to use mup-aws-beanstalk with a react-native when the backend is meteor ? #149

Open nwabdou85 opened 2 years ago

nwabdou85 commented 2 years ago

Hi,

My react native application use meteor as backend, with the time the load increase which decrease performance; I hope benefit from the auto scaling option of aws using map-aws-beanstlak;

It appears based on documentation that we can use it with web application; can we use it, also, for the mobile ? and how (if yes)?

concretely, how to handle this scenario? :

@zodern your help is very appreciated;

Thank you every one;

paulincai commented 2 years ago

@nwabdou85 just curious why you need IP addresses? I am not familiar with deploying RN Meteor projects but I am pretty ok with the web.

I will explain briefly how Elastic Beanstalk works: You have an Application Load Balancer that receives your clients. The URL is found in your EBS project. At ALB level you can configure rules and you can use the same ALB as a shared ALB for multiple subdomains. ALB distributes your connections and based on your capacity rules in the EBS, you will scale up or down. All those EC2 machines behind the ALB have internal IPs that you will want to keep away from the internet. ALB receives HTTPS (443) and directs internally to HTTP(80). Output from your EC2s is HTTPS to all internet. Your EC2 machines sit in Security Groups so your ALB directs actually to a Security Group with in/out rules. When your EBS adds machines by scaling up, those machines are being added to the Security Group so you always direct traffic based on the Security Group and not the machine directly.

Ok, there is no way to know your EC2 IPs in advance, you could allocate elastic IPs to your initial set of machines (if you don't use autoscalling) but you cannot allocate elastic (static public) IPs to machines as they are being created. What you can work with is the DNS of your EBS and this you can map to a URL of your app (from your DNS provider).

Mongo: if you need to run your own, you create a new security group in the same VPC as your App, add a EC2 of your preferred configuration install your mongo and you will end up with a local url or IP (can be non-SSL) that you will have to make sure it is in the same VPC as your EBS EC2 machines (same VPC means you are secured inside the VPC).

Conclusion: ROOT_URL is your EBS address (ends with '.elasticbeanstalk.com ' or your app address mapped to your EBS URL)

nwabdou85 commented 2 years ago

This is a great reply from you @paulincai , thank you for your time; I don't not necessarily need ip but url from ebs may make the day;

Do you have an example to follow ? even if it's for the web (it's my first time doing this);

paulincai commented 2 years ago

Try to start with this configuration in your mup.js and try to have your initial EBS created. Then you will have to configure the Load Balancer policy and the Security Group Policy. Simply put, Load Balancer takes from HTTP and directs to HTTPS, takes HTTPS. All is directed to Security Group (member of which your EC2 machines will be). Anyway, if you have a successful deploy, get back here if you don't manage to set the rest.

module.exports = {
  app: {
    // Tells mup that the AWS Beanstalk plugin will manage the app
    type: 'aws-beanstalk',
    name: 'your_app_name',
    path: '../',
    region: 'eu-central-1',
    env: {
      ROOT_URL: 'url_of_beanstalk', // or a url mapped to the beanstalk URL
      MONGO_URL: 'mongodb://......./meteor?retryWrites=true&w=majority&connectTimeoutMS=60000&socketTimeoutMS=60000',
      MONGO_OPLOG_URL: 'mongodb://..........',
      MONGO_OTHER_CONTENT_URL: 'mongodb://.....',
      MAIL_URL: 'smtps://.....'
    },
    auth: {
      id: '........',
      secret: '.........'
    },
    customBeanstalkConfig: [
      {
        namespace: 'aws:autoscaling:trigger',
        option: 'LowerThreshold',
        value: '1'
      },
      {
        namespace: 'aws:elasticbeanstalk:cloudwatch:logs',
        option: 'StreamLogs',
        value: 'false'
      },
      {
        namespace: 'aws:elasticbeanstalk:command',
        option: 'DeploymentPolicy',
        value: 'AllAtOnce' // use your own desired scenario
      },
      {
        namespace: 'aws:autoscaling:launchconfiguration',
        option: 'InstanceType',
        value: 't2.nano' // your preferred size.
      },
      {
        namespace: 'aws:ec2:instances',
        option: 'EnableSpot',
        value: 'false'
      },
      {
        namespace: 'aws:autoscaling:updatepolicy:rollingupdate',
        option: 'RollingUpdateEnabled',
        value: 'false'
      },
      {// if you need a shared balancer that already exists
        namespace: 'aws:elasticbeanstalk:environment',
        option: 'LoadBalancerIsShared',
        value: 'true'
      },
      { // if you need a shared balancer that already exists
        namespace: 'aws:elbv2:loadbalancer',
        option: 'SharedLoadBalancer',
        value: 'arn:aws:elasticloadbalancing:eu-central-1:.............'
      },
      {
        namespace: 'aws:autoscaling:launchconfiguration',
        option: 'RootVolumeSize',
        value: '20'
      }
    ],
    minInstances: 1,
    maxInstances: 1,
    oldVersions: 3,
    forceSSL: true
  },
  plugins: ['mup-aws-beanstalk']
}
nwabdou85 commented 2 years ago

Thank you @paulincai ; 1 - I think I ve a issue with the traffic but don't know how to fixe it; here is the log

Env Event: Updating environment mup-*'s configuration settings. Env Event: Created Auto Scaling launch configuration named: awseb-e-*** Env Event: Auto Scaling group update progress: Temporarily setting autoscaling group MinSize and DesiredCapacity to 3. Env Event: Auto Scaling group update progress: Rolling update initiated. Terminating 3 obsolete instance(s) in batches of 1, while keeping at least 1 instance(s) in service. Waiting on resource signals with a timeout of PT30M when new instances are added to the autoscaling group. Env Event: Added instance [i-0b**] to your environment. Env Event: Auto Scaling group update progress: New instance(s) added to autoscaling group - Waiting on 1 resource signal(s) with a timeout of PT30M. Env Event: Removed instance [i-0**] from your environment. Env Event: Environment health has transitioned from Severe to Degraded. ELB processes are not healthy on 3 out of 4 instances. Application update in progress on 1 instance. 0 out of 4 instances completed (running for 2 minutes). No data received from 3 out of 4 instances. 50.0 % of the requests to the ELB are failing with HTTP 5xx. Insufficient request rate (2.0 requests/min) to determine application health (4 minutes ago). ELB health is failing or not available for 3 out of 4 instances. Env Event: Still waiting for the following 1 instances to become healthy: [I-]. Env Event: Still waiting for the following 1 instances to become healthy: [I-*]. Env Event: Environment health has transitioned from Degraded to Severe. ELB processes are not healthy on all instances. Application update in progress on 1 instance. 0 out of 3 instances completed (running for 11 minutes). None of the instances are sending data. ELB health is failing or not available for all instances. Env Event: Still waiting for the following 1 instances to become healthy: [I***]. Env Event: Still waiting for the following 1 instances to become healthy: [I-*****].

2 - for the mongo , I did something like this MONGO_URL: 'mongodb://mongodb/meteor', are the other instance can access it when scaling ?

your help is more appreciate ;

paulincai commented 2 years ago

Hi @nwabdou85,

  1. If that is your MONGO_URL and you have 3 machines running where each machine connects to?
  2. It is pretty hard to explain the ALB (the load balancer). You need to have a minimum understanding of EC2. I failed so many times before I learned how to do it ... I find it impossible to explain it in words although it is not complicated. It just requires to stick to the exact logic.

Anyway, you need a Mongo DB to which you are able to connect all your machines. I'd suggest you start with an external DB that you can get for free from Mongo Atlas and once you have a running app, you can run your own Mongo server. If you are not planning for many tens of thousands of concurrent connections, EBS might be useless super scaling.

nwabdou85 commented 2 years ago

@paulincai Should I create a listener to redirect from http to https (or the opposite)? I still see unhealthy status (Health checks failed) with port 80;

nwabdou85 commented 2 years ago

For those may have the same problem; I fix it by attach AmazonS3FullAccess strategy to IAM management console

1tac11 commented 11 months ago

So I have to set the DNS Server of the EBS in my dns-provider? No up address or ipv6 necessary?