al2023にnode.jsの環境を構築する
1.AMIからEC2を起動
public AMIを検索して、最新のal2023のAMIを使用
現時点では下記
- ami-03f584e50b2d32776
al2023-ami-2023.6.20241010.0-kernel-6.1-x86_64
2.node.js関連のソフトウェアをインストール
EC2にsshログインしする
コマンドによってはカレントディレクトリにnode.js用のディレクトリが作られるので
node.jsのコードを配置したいディレクトリに移動して実行すること
下記コマンドを実行
■nvmインストール
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
■nvmをロード
source ~/.bashrc
■TLSインストール
nvm install --lts
■動作確認
node -v
バージョンが表示されればOK
npm -v
バージョンが表示されればOK
node -e "console.log('Running Node.js ' + process.version)"
Running Node.js [version]
と出ればOK
■yarnインストール
npmは自動でインストールされているが、古いサービスなのでyarnに乗り換える
npm install -g yarn
yarn -v
バージョンが表示されればOK
yarn init
色々聞かれるが全部空欄エンターでOK
カレントディレクトリに「package.json」が作られていればOK
3.httpの環境構築
■httpモジュールのインストール
yarn add http
カレントディレクトリに以下が作られていればOK
├ node_modules
├ package.json
└ yarn.lock
4.jsプログラム実行
■jsファイルを作成
同じ場所にserver.jsと言うファイルを作成
中身には以下を記述
console.log("hello world!!");
■実行
node server.js
hello world!!
と表示されればOK


Great tip on finding the latest al2023 AMIs! I always struggle to keep up. For anyone looking to automate this process, consider incorporating the search into your cloud infrastructure as code. It's like building your own highly customized, automated Drift Boss of AMI selection! https://driftboss.lol