Deploy Angular 2 EC2 Application

I hope this is the right place to ask this question, please move or delete this post if it is not.

I am trying to create a simple website that can handle basic POST and GET requests using Angular 2 and Amazon EC2. I have a lot of experience with the web application interface in Angular 2, but little experience connecting to the back end and running it on an Amazon EC2 instance.

I was hoping to find an example or some resources that would explain how to use the HTTP service with some kind of basic infrastructure. I know that Angular contains examples of how to use the HTTP service, but it's hard to imagine how this setting should work to handle these requests, as well as how to properly configure this setting on EC2. Any help or resources would be greatly appreciated!

+4
source share
2 answers

Frontend / Client

@glavan, AWS S3 SPA, angular 2 . SPA. , SPA S3. angular.

Backend

AWS EC2 - . . , , EC2, VPC Elastic-ip - .

SPA -, .. backend API CRUD . , serverless. 5 . AWS - , . AWS + API- + DynamoDB.

,: , , POST URL- . AWS lambda POST , dynamoDB. , API ( AWS). API, angular 2 APP. SO, POST, angular 2 → API → Lambda ( ) → dynamoDB.

EC2.

  • (EC2) , . Serverless - .
  • -. , - , .

, -. .

+4

.

beanstalk nodejs ec2, , , , , , :

  • , , /usr/bin/env: node: No such file or directory, script

.ebextensions/angular2deployment.config

files:
  "/opt/elasticbeanstalk/env.vars" :
    mode: "000775"
    owner: root
    group: users
    content: |
      export NPM_CONFIG_LOGLEVEL=error
      export NODE_PATH=`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: users
    content: |
      #!/bin/bash
      . /opt/elasticbeanstalk/env.vars
      function error_exit
      {
        eventHelper.py --msg "$1" --severity ERROR
        exit $2
      }

      #install not-installed yet app node_modules
      if [ ! -d "/var/node_modules" ]; then
        mkdir /var/node_modules ;
      fi
      if [ -d /tmp/deployment/application ]; then
        ln -s /var/node_modules /tmp/deployment/application/
      fi

      OUT=$([ -d "/tmp/deployment/application" ] && cd /tmp/deployment/application && $NODE_PATH/node $NODE_PATH/npm install 2>&1) || error_exit "Failed to run npm install.  $OUT" $?
      echo $OUT
  "/opt/elasticbeanstalk/hooks/configdeploy/pre/50npm.sh" :
    mode: "000666"
    owner: root
    group: users
    content: |
       #no need to run npm install during configdeploy
  1. node_modules dist, , .
  2. npm install && npm start ( ), , angular2 package.json . Angular.IO Deployment
  3. # 3 , node_modules
  4. (, .ebextensions), , ( , )
  5. !

MacOS , macos macos, , , , , YemuZip

: beanstalk EC2 npm install npm start, ,

+2

Source: https://habr.com/ru/post/1655638/


All Articles