コンテナを爆速にデプロイできる「AWS App Runner」を使ってみた【マネコン】【AWS CLI】

記事タイトルとURLをコピーする

こんにちは。AWS CLIが好きな福島です。

今回は、約3週間前に登場したAWS App Runnerという新サービスをマネジメントコンソールとCLIから使ってみたので、その内容をブログに記載いたします。

AWS が AWS App Runner を発表

参考

AWS App Runner のご紹介 | Amazon Web Services ブログ

App Runnerとは

ソースコードやコンテナイメージを使用して、アプリケーションを簡単にデプロイできるマネージドサービスです!

ということで、爆速で本題に入っていきます。

マネージメントコンソール編

①「サービスの作成」をクリックします。

f:id:swx-fukushima:20210605030407p:plain

②ソースの設定

「Amazon ECR パブリック」をクリックします。
「コンテナイメージのURI」に「public.ecr.aws/aws-containers/hello-app-runner:latest」を入力します。 f:id:swx-fukushima:20210605030502p:plain

③サービスの設定

「サービス名」に任意の値を入力します。
「ポート」には、「8000」を指定します。 f:id:swx-fukushima:20210605030651p:plain

仮想CPUは、1,2vCPUが選択できます。
メモリは、2,3,4GBが選択できます。

④その他の設定

今回は、デフォルトのままいきますが、以下の設定もできます。

・AutoScalingの設定
・ロードバランサーのヘルスチェックの設定
・インスタンスのロールの設定
・KMSを使ったデータの暗号化

f:id:swx-fukushima:20210605030746p:plain

⑤作成とデプロイ

設定のサマリを確認し、「作成とデプロイ」をクリックします。

f:id:swx-fukushima:20210605031038p:plain

⑥動作確認

ステータスが「Running」になることを確認し、デフォルトドメインにアクセスします。

f:id:swx-fukushima:20210605032158p:plain

無事にアクセスできました!!! f:id:swx-fukushima:20210605032259p:plain

App Runnerのその他の情報

ログ

以下のログが見れます。

・イベントログ
・デプロイログ
・アプリケーションログ

f:id:swx-fukushima:20210605043712p:plain

メトリクス

以下のメトリクスを確認することもできます。

・Request count
・HTTP 2xx response count
・HTTP 4xx response count
・HTTP 5xx response count ・Request latency
・Active instances

画像は、Request latencyとActive instancesのメトリクス。

f:id:swx-fukushima:20210605044118p:plain

カスタムドメイン

カスタムドメインも5つまで設定できるようです。

f:id:swx-fukushima:20210605044205p:plain

CLI編

①「hello-app-runner.json」という名前でファイルを作成します。

ファイルの中身

{
    "ServiceName": "hello-app-runner",
    "SourceConfiguration": {
        "ImageRepository": {
            "ImageIdentifier": "public.ecr.aws/aws-containers/hello-app-runner:latest",
            "ImageRepositoryType": "ECR_PUBLIC",
            "ImageConfiguration": {
                "Port": "8000"
            }
        },
        "AutoDeploymentsEnabled": false
    }
}

②コマンドを実行します。

aws apprunner create-service --cli-input-json file://hello-app-runner.json

実行結果)

{
    "Service": {
        "ServiceName": "hello-app-runner",
        "ServiceId": "42010c9af09a484ea4cb2f1ac2b5a91e",
   ★ "ServiceArn": "arn:aws:apprunner:ap-northeast-1:xxxxxxxxxxxx:service/hello-app-runner/42010c9af09a484ea4cb2f1ac2b5a91e",
        "ServiceUrl": "w2iyamquyd.ap-northeast-1.awsapprunner.com",
        "CreatedAt": "2021-06-05T04:17:05.715000+09:00",
        "UpdatedAt": "2021-06-05T04:17:05.715000+09:00",
        "Status": "OPERATION_IN_PROGRESS",
        "SourceConfiguration": {
            "ImageRepository": {
                "ImageIdentifier": "public.ecr.aws/aws-containers/hello-app-runner:latest",
                "ImageConfiguration": {
                    "Port": "8000"
                },
                "ImageRepositoryType": "ECR_PUBLIC"
            },
            "AutoDeploymentsEnabled": false
        },
        "InstanceConfiguration": {
            "Cpu": "1024",
            "Memory": "2048"
        },
        "HealthCheckConfiguration": {
            "Protocol": "TCP",
            "Path": "/",
            "Interval": 5,
            "Timeout": 2,
            "HealthyThreshold": 1,
            "UnhealthyThreshold": 5
        },
        "AutoScalingConfigurationSummary": {
            "AutoScalingConfigurationArn": "arn:aws:apprunner:ap-northeast-1:xxxxxxxxxxxxxx:autoscalingconfiguration/DefaultConfiguration/1/00000000000000000000000000000001",
            "AutoScalingConfigurationName": "DefaultConfiguration",
            "AutoScalingConfigurationRevision": 1
        }
    },
    "OperationId": "e2d2af0cac3d4c60b580033886dc083e"
}

ステータスチェックの際に利用するので、ServiceArnを変数に定義しておきます。

SERVICEARN="上記出力に含まれているServiceArn"

実行例)

SERVICEARN=arn:aws:apprunner:ap-northeast-1:xxxxxxxxxxxx:service/hello-app-runner/42010c9af09a484ea4cb2f1ac2b5a91e

③ステータス確認。

aws apprunner describe-service --service-arn $SERVICEARN --query "Service.{ServiceName:ServiceName,Status:Status,ServiceUrl:ServiceUrl}" --output table

実行結果)

-------------------------------------------------------------------------------
|                               DescribeService                               |
+-------------------+----------------------------------------------+----------+
|    ServiceName    |                 ServiceUrl                   | Status   |
+-------------------+----------------------------------------------+----------+
|  hello-app-runner |  w2iyamquyd.ap-northeast-1.awsapprunner.com  |  RUNNING |
+-------------------+----------------------------------------------+----------+

④動作確認。

③の出力結果であるServiceUrlにアクセスします。

curl https://xxxxxxxxx.ap-northeast-1.awsapprunner.com

実行結果)

# curl https://w2iyamquyd.ap-northeast-1.awsapprunner.com

   ______                             __        __      __  _                  __
  / ____/___  ____  ____ __________ _/ /___  __/ /___ _/ /_(_)___  ____  _____/ /
 / /   / __ \/ __ \/ __ `/ ___/ __ `/ __/ / / / / __ `/ __/ / __ \/ __ \/ ___/ /
/ /___/ /_/ / / / / /_/ / /  / /_/ / /_/ /_/ / / /_/ / /_/ / /_/ / / / (__  )_/
\____/\____/_/ /_/\__, /_/   \__,_/\__/\__,_/_/\__,_/\__/_/\____/_/ /_/____(_)
                 /____/


        Congratulations, your service has successfully deployed on AWS App Runner.



Open it in your browser at https://w2iyamquyd.ap-northeast-1.awsapprunner.com/

Try the workshop at https://apprunnerworkshop.com
Read the docs at https://aws.amazon.com/apprunner
#

料金

主に、CPUとメモリ、リクエストの処理数に応じて、料金がかかります。 App Runnerは停止することが可能です。

停止している場合

0USD

起動している場合(リクエストがない場合

東京リージョンの場合、
メモリ1GBあたり、0.009USD/時
かかります。
※東京リージョンは他リージョンに比べて少し高いです。

起動している場合(リクエストがある場合

東京リージョンの場合、
・1vCPUあたり、0.081USD/時
・メモリ1GBあたり、0.009USD/時
かかります。
※東京リージョンは他リージョンに比べて少し高いです。

→リクエストがあると、vCPUの料金が上乗せされるイメージです。

その他

自動デプロイ:1 USD/アプリケーション、月額
ビルド時間:0.005 USD/ビルド時間 (分)
他の AWS サービスおよびデータ転送の利用

AWS App Runner の料金 – フルマネージド型のコンテナアプリケーションサービス - Amazon Web Services

終わりに

SGの設定ができなそうだったので、アクセス制御が必要な場合は、注意が必要そうですが、手軽にコンテナをデプロイできるのは良いですね!

福島 和弥 (記事一覧)

2019/10 入社

AWS CLIが好きです。

AWS資格12冠。2023 Japan AWS Partner Ambassador/APN ALL AWS Certifications Engineer。