AWS App RunnerのサービスをAWS Copilotで起動させてみた

こんにちは。サービスグループの武田です。コンテナ化されたWebアプリケーションなどを手軽に実行できる新しいサービス、AWS App RunnerがAWS Copilotからも起動できるとのことで試してみました。



コンテナ化されたWebアプリケーションなどを手軽に実行できる新しいサービス、AWS App Runnerがローンチされましたね!

ドキュメントを読んでいるとAWS Copilotからも簡単に起動できるよといったことが書かれていたため、試してみました。


手元の環境にはAWS Copilotがインストールされていなかったので、今回はAWS CloudShellで実行しました。ところで、CloudShellにプリインストールされているCopilotはv1.2.0です。

$ copilot --version
copilot version: v1.2.0

リリースを追ってみたところ、App Runnerがサポートされるのはv1.7.0以降のようです。というわけでアップデートしましょう。

$ sudo curl -Lo /usr/local/bin/copilot \
   && sudo chmod +x /usr/local/bin/copilot \
   && copilot --version 
copilot version: v1.7.0


$ mkdir .aws
$ echo '[default]' >> .aws/config



$ copilot init
Note: It's best to run this command in the root of your Git repository.
Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with a containerized application on AWS. An application is a collection of
containerized services that operate together.
  What would you like to name your application? [? for help] hello-app-runner
  Which workload type best represents your architecture?  [Use arrows to move, type to filter, ? for more help]
  > Request-Driven Web Service  (App Runner)
    Load Balanced Web Service   (Internet to ECS on Fargate)
    Backend Service             (ECS on Fargate)
    Scheduled Job               (Scheduled event to State Machine to Fargate)
  What do you want to name this Request-Driven Web Service? [? for help] nginx
  What's the location of the image to use? [? for help]
  Which port do you want customer traffic sent to? [? for help] (80)



Ok great, we'll set up a Request-Driven Web Service named nginx in application hello-app-runner listening on port 80.

✔ Created the infrastructure to manage services and jobs under application hello-app-runner.

✔ Wrote the manifest for service nginx at copilot/nginx/manifest.yml
Your manifest contains configurations like your container size and port (:80).

✔ Created ECR repositories for service nginx.

All right, you're all set for local development.

  Would you like to deploy a test environment? [? for help] (y/N) y

Deploy: Yes

✔ Proposing infrastructure changes for the hello-app-runner-test environment.
- Creating the infrastructure for the hello-app-runner-test environment.  [create complete]  [82.8s]
  - An IAM Role for AWS CloudFormation to manage resources                [create complete]  [21.9s]
  - An ECS cluster to group your services                                 [create complete]  [10.9s]
  - Enable long ARN formats for the authenticated AWS principal           [create complete]  [2.4s]
  - An IAM Role to describe resources in your environment                 [create complete]  [21.9s]
  - A security group to allow your containers to talk to each other       [create complete]  [4.4s]
  - An Internet Gateway to connect to the public internet                 [create complete]  [16.4s]
  - Private subnet 1 for resources with no internet access                [create complete]  [18.6s]
  - Private subnet 2 for resources with no internet access                [create complete]  [18.6s]
  - Public subnet 1 for resources that can access the internet            [create complete]  [18.6s]
  - Public subnet 2 for resources that can access the internet            [create complete]  [18.6s]
  - A Virtual Private Cloud to control networking of your AWS resources   [create complete]  [16.4s]
✔ Created environment test in region ap-northeast-1 under application hello-app-runner.
Environment test is already on the latest version v1.4.0, skip upgrade.
✔ Proposing infrastructure changes for stack hello-app-runner-test-nginx
- Creating the infrastructure for stack hello-app-runner-test-nginx        [create complete]  [266.6s]
  - An IAM role to control permissions for the containers in your service  [create complete]  [17.6s]
  - An App Runner service to run and manage your containers                [create complete]  [239.8s]
✔ Deployed nginx, you can access it at






# The manifest for the "nginx" service.
# Read the full specification for the "Request-Driven Web Service" type at:

# Your service name will be used in naming your resources like log groups, App Runner services, etc.
name: nginx
# The "architecture" of the service you're running.
type: Request-Driven Web Service

  # The name of the Docker image.
  # Port exposed through your container to route traffic to it.
  port: 80

# http:
#   healthcheck:
#     path: /
#     healthy_threshold: 3
#     unhealthy_threshold: 5
#     interval: 10s
#     timeout: 5s

# Number of CPU units for the task.
cpu: 1024
# Amount of memory in MiB used by the task.
memory: 2048

# Optional fields for more advanced use-cases.
# variables:                    # Pass environment variables as key value pairs.
#   LOG_LEVEL: info
# tags:                         # Pass tags as key value pairs.
#   project: project-name

# You can override any of the values defined above by environment.
# environments:
#   test:
#     variables:
#       LOG_LEVEL: debug        # Log level for the "test" environment.


Copilotの仕様上、環境を作成すると自動的にVPCやECSクラスターが自動的に作成されます。おそらくこれを抑制する手段は今のところありません。使わないリソースの作成を避けたい方は、CopilotではなくマネジメントコンソールないしはAWS CLIなどを利用した方がよいでしょう。とはいえ、料金が発生するわけではありません。管理方法なども含め検討してください。