0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Fargate AWSCLIでサービス作成/削除

Last updated at Posted at 2021-12-13

ネットワークリソースとロードバランサーの指定が若干面倒だったのでメモ

サービス作成

リファレンス
https://docs.aws.amazon.com/cli/latest/reference/ecs/create-service.html

コマンド例

service=xxxxxxxx
aws ecs create-service \
    --cluster CLUSTER \
    --task-definition TASKDEF \
    --service-name $service \
    --desired-count 1 \
    --launch-type FARGATE \
    --network-configuration "awsvpcConfiguration={subnets=[subnet-XXXXXXXX,subnet-XXXXXXXX],securityGroups=[SG-XXXXXXXX],assignPublicIp=ENABLED}" \
    --load-balancers "targetGroupArn="arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxxxx:targetgroup/TargetGroup/xxxxxxxx",containerName=CONTAINER,containerPort=80" \
    --enable-execute-command > /dev/null

説明

  • サービス名だけ変数指定(検証時に連続で作り直すとき、サービスの削除に時間がかかる間、同じサービス名でサービスを作成しようとすると待たされるので、都度違うサービス名を指定できるよう)
  • タスクを起動するサブネットを2つ指定する
  • プライベートサブネット指定でもassignPublicIp=ENABLEDにしている
  • ターゲットグループARNとロードバランサ名--load-balancersのどちらかを指定するんだけど、ロードバランサ名の方で指定すると以下エラーがでるのはなんでだろ。ここではターゲットグループARNで指定
    • An error occurred (InvalidParameterException) when calling the CreateService operation: Classic Load Balancers are not supported with Fargate.
    • ちなみに両方指定すると以下エラー
      • An error occurred (InvalidParameterException) when calling the CreateService operation: loadBalancerName and targetGroupArn cannot both be specified. You must specify either a loadBalancerName or a targetGroupArn.
  • ECS Exec有効
  • 正常実行後に自動的にJSONがページャで開かれるのがいらないので、標準出力を/dev/nullに送ってすぐプロンプトが戻るようにする

サービス削除

先にdesired-countを0にしてから、サービスを削除する。
どちらも実行後に自動的にJSONをページャで開くのがいらないので標準出力を/dev/nullに送る

aws ecs update-service --cluster CLUSTER --service $service --desired-count 0 > /dev/null
aws ecs delete-service --cluster CLUSTER --service $service > /dev/null
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?