Finch を使用した ECR 経由の AppRunner へのデプロイする。

2023.09.12

Finch

Finchは、Linuxコンテナのビルド、実行、および公開のための新しいコマンドラインクライアントです。これは、ネイティブなmacOSクライアントの簡単なインストールを提供します

デプロイする

Finchを使用して構築されたコンテナを使用して、単純な応答HelloAppRunnerを提供する基本的なNode.jsアプリケーションをデプロイしましょう。

Finchをインストールし、初期化し、起動しましょう。

回はmacOS Ventura 13.4.1 (c) 環境で試しました。FinchをインストールするためにHomebrewを使用します。
  • インストール
    • brew install --cask finch
  • 初期化する
    • finch vm init
  • Finchを起動する
    • finch vm start

インストールに関する詳細情報は、次のリンクをご参照ください https://github.com/runfinch/finch

コード

このブログにおいて

フォルダ名 = 20230829

/app.js

const express=require('express');
const app=express();
app.use(express.json());

app.get('/hello',(req,res)=>{
try {
return res.status(200).send("Hello AppRunner");
} catch (error) {
return res.status(500);
}
});
module.exports=app;

/Containerfile

# Use an official Node.js image as the base
FROM node:14

# Set the working directory within the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the container
COPY package*.json ./

# Install app dependencies
RUN npm install

# Copy the rest of the application code into the container
COPY . .

# Expose the port that the app will run on
EXPOSE 3000

# Define the command to start your Node.js app using nodemon
CMD ["npx", "nodemon", "server.js"]

/server.js

const app=require('./app')
app.listen(3000);

/package.json

{
  "name": "20230829",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\exit 1",
    "start":"npx nodemon server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "nodemon": "^3.0.1"
  }
}

ECR リポジトリ

私たちはそのイメージのためにパブリックリポジトリを作成します。

ここでは、ビューとプッシュのコマンドを示しますが、dockerの代わりにfinchとfinchイメージを使用します。イメージを表示するには、finchイメージをリストアップしましょう。

finch image ls

イメージのURIをコピーしましょう。

AppRunner サービスを作成する手順

  • サービスの作成を選択してください
  • ソースと展開で、以下の画像に示されているオプションを選択し、指定されたコンテナイメージURIボックスにイメージURIを貼り付けてください。
  • 設定でサービス名を指定し、ポートを3000に変更し、その他の設定はデフォルトのままにしてください。
  • コマンドを確認した後、作成およびデプロイを行いましょう。

AppRunner サービスを実行中

ステータスが実行中の場合、デフォルトドメインを開き、/hello を追加すると出力が表示されます。

参考文献:

https://github.com/runfinch/finch

https://aws.amazon.com/jp/blogs/news/introducing-finch-an-open-source-client-for-container-development/

https://dev.classmethod.jp/articles/the-finch-cli-cheat-sheet-v0-4-1/