あなたのノードJSアプリをAWSエラスティック


今日、我々は簡単なAPIをAWSの弾力性ビーン茎サービスに配備する方法を学びます.

前提条件
AWSに登録するGuide here
インストールdownload
EB CLIインストールInstallation Guide here
eb cliとgit cliがマシンにインストールされているかどうかを調べます.



セットアップnpm init -y あなたのアプリケーションを初期化する.
クリックhere シンプルエクスプレススターターhello world アプリ.

インストールexpress このコードをパッケージに入れてダンプしますindex.js ファイル

const express = require('express')
const app = express()
const port = process.env.PORT|| 3000;

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

スタートスクリプトを書きましょうpackage.json
クリエイトア.gitignore ファイルを追加します
node_modules/
.gitignore
.elasticbeanstalk/

Gitセットアッププロジェクト
  • 国際通貨基金
  • Git add
  • 最初のコミット"

  • 弾性beanstalk AWSインスタンスの展開


    AWSインスタンスを初期化する方法を見てみましょう.
    EB INITフラグを実行する

    eb init --platform node.js --region us-east-2


    上記のコマンドは.elasticbeanstalk folder

    拡張モジュール
    電子メールの初期化後、フォルダを作成.ebextensions とファイルnodecommands.config我々のスタートコマンドをnodecommands.config
    option_settings:
        aws:elasticbeanstalk:container:nodejs:
            NodeCommand: "npm start"
    

    アプリケーション環境を作成する


    eb create [environment-name]
    The is the name of your application, in this example I used elasticbean hence the command is [eb create elasticbean]

  • フラグを実行します.
  • 注意:使用を避ける_ プロジェクトフォルダの名前


    アプリケーションの配備


    eb deploy



    EBアプリを開くには

    eb open


    コマンド


    EBログ
    EBヘルプ
    注意:角括弧を含まない

    EB initプロジェクトを削除するには

    Go to the directory of your project (the directory where you originally ran the "eb init" command). Delete the . elasticbeanstalk directory. You can now run "eb init" again, and it will prompt you for your configuration information.



    結論
    このガイドが役に立つことを願っています.読書ありがとう


    資源
    Deploy Express app on aws