この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
AWS Fargateでコンテナをデプロイ
新サービス「AWS Fargate」に対して、ECS CLIを使ってデプロイしてみました! 1.1.0 からサポートしており、先ほどアップデートがありました。
ECS CLIのインストール
最新バージョンに上げます。
$ sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest
$ ecs-cli --version
ecs-cli version 1.1.0 (4f176a7)
Fargateのクラスタを立ち上げる
Fargateを使える状態にするため、クラスタを立ち上げます。
$ ecs-cli up --launch-type FARGATE
INFO[0003] Created cluster cluster=rising-FrontendEcsStack-BQ9SRI1OEYTX-FrontendEcsCluster-XEX7GOXOIFQC region=us-east-1
INFO[0005] Waiting for your cluster resources to be created...
INFO[0005] Cloudformation stack status stackStatus="CREATE_IN_PROGRESS"
INFO[0067] Cloudformation stack status stackStatus="CREATE_IN_PROGRESS"
Cluster creation succeeded.
VPC created: vpc-0b7f1d73
Subnet created: subnet-xxxxxxxx
Subnet created: subnet-yyyyyyyy
このコマンドを実行するだけで、以下のリソースがプロビジョニングされます。
- EC2 VPC
- EC2 Internet Gateway
- EC2 VPC Gateway Attachment
- EC2 Route Table
- EC2 Route
- 2 Public EC2 Subnets
- 2 EC2 SubnetRouteTableAssocitaions
docker-compose.yml を用意する
サンプルを参考に docker-compose.yml
を用意します。
version: '2'
services:
web:
image: amazon/amazon-ecs-sample
ports:
- "80:80"
ecs-param.yml を用意する
docker-compose.yml ではなく ecs-param.yml で定義するようになりました。
version: 1
task_definition:
ecs_network_mode: awsvpc
task_execution_role: ecsTaskExecutionRole
task_size:
cpu_limit: 512
mem_limit: 2GB
services:
web:
essential: true
run_params:
network_configuration:
awsvpc_configuration:
subnets:
- subnet-xxxxxxxx
- subnet-yyyyyyyy
security_groups:
- sg-xxxxxxxx
assign_public_ip: ENABLED
ECS CLIからデプロイしてみる
サービスを立ち上げます。
$ecs-cli compose service up
WARN[0000] Skipping unsupported YAML option... option name=networks
WARN[0000] Skipping unsupported YAML option for service... option name=networks service name=web
INFO[0001] Using ECS task definition TaskDefinition="fargate:3"
INFO[0001] Updated ECS service successfully desiredCount=1 serviceName=fargate
INFO[0032] (service fargate) has started 1 tasks: (task d8a01acc-6b68-445a-b116-d847a2b5d751). timestamp=2017-11-29 23:53:08 +0000 UTC
INFO[0108] Service status desiredCount=1 runningCount=1 serviceName=fargate
INFO[0108] ECS Service has reached a stable state desiredCount=1 runningCount=1 serviceName=fargate
デプロイに成功しました!
まとめ
ECS CLIを使っている人は導入コストが少なく、今までのECSと同様にデプロイできます。お試しあれ!