LoginSignup
0
0

More than 1 year has passed since last update.

【AWS】AWS Batch(Fargate タイプ)の CLI コマンドメモ

Posted at

初めに

コマンドを調べるのが大変なのでメモしておきます。

実行環境

  • CloudShell

手順

Important

バックスラッシュ前のスペース有無は重要です。

  • オプション前行の行末は、 \ (スペース + バックスラッシュ)とすること。

NG

aws batch create-compute-environment\  ←バックスラッシュ前にスペースが必要
--compute-environment-name demo-computing-env

OK

aws batch create-compute-environment \
--compute-environment-name demo-computing-env
  • オプションに対する値の途中の行末は、バックスラッシュ前にスペースを入れないこと。

NG

aws batch create-compute-environment \
--compute-resources type=FARGATE,maxvCpus=256, \  ←バックスラッシュ前にスペースは不要
subnets=subnet-xxxxxxxx,subnet-yyyyyyyyy,subnet-zzzzzzzz,securityGroupIds=sg-wwwwwwww

OK

aws batch create-compute-environment \
--compute-resources type=FARGATE,maxvCpus=256,\
subnets=subnet-xxxxxxxx,subnet-yyyyyyyyy,subnet-zzzzzzzz,securityGroupIds=sg-wwwwwwww

1. 準備

  • アカウント ID を取得する
AWS_ACCOUNT_ID=`aws sts get-caller-identity | jq -r .Account`
  • リージョンを取得する
AWS_REGION=`curl -s http://169.254.169.254/task/TaskARN | cut -d ":"  -f 4`

2. コンピューティング環境作成

aws batch create-compute-environment \
--compute-environment-name demo-computing-env \
--type MANAGED --state ENABLED \
--service-role arn:aws:iam::${AWS_ACCOUNT_ID}:role/aws-service-role/batch.amazonaws.com/AWSServiceRoleForBatch \
--compute-resources type=FARGATE,maxvCpus=256,\
subnets=subnet-xxxxxxxx,subnet-yyyyyyyyy,subnet-zzzzzzzz,securityGroupIds=sg-wwwwwwww

3. ジョブキュー作成

aws batch create-job-queue \
--job-queue-name demo-job-queue \
--priority 1 \
--state ENABLED \
--compute-environment-order order=1,computeEnvironment=demo-computing-env

4. ジョブ定義作成

aws batch register-job-definition \
--job-definition-name demo-job-def \
--type container \
--platform-capabilities FARGATE \
--container-properties image=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/sage-demo:latest,\
executionRoleArn=arn:aws:iam::${AWS_ACCOUNT_ID}:role/ecsTaskExecutionRole,\
jobRoleArn=arn:aws:iam::${AWS_ACCOUNT_ID}:role/ecsJobRole,\
environment="[{name=S3_BUCKET,value=demo-bucket}]",\
resourceRequirements="[{type=VCPU,value=1.0},{type=MEMORY,value=2048}]",\
command=sh,run.sh,\
logConfiguration={logDriver=awslogs},\
networkConfiguration={assignPublicIp=ENABLED},\
fargatePlatformConfiguration={platformVersion=LATEST}

Note

  • fargatePlatformConfiguration={platformVersion=LATEST}

fargatePlatformConfiguration="{platformVersion=LATEST}" のようにダブルクォーテーションがあってもよいです。

Warning

  • environment="[{name=S3_BUCKET,value=demo-bucket}]"

environment=[{name=S3_BUCKET,value=demo-bucket}] ではエラーが発生します。ダブルクォーテーションが必要です。

5. ジョブ送信

aws batch submit-job \
--job-name demo-job \
--job-queue demo-job-queue \
--job-definition demo-job-def \
--container-overrides environment="[{name=DEGREE,value=3},{name=MAX_TIMES,value=2}]"

参考記事

  • コンピューティング環境作成

  • ジョブキュー作成

  • ジョブ定義作成

  • ジョブ

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