AWS ParallelCluster v3 カスタムブートストラップ用のS3バケット指定方法

2021.09.18

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

AWS ParallelCluster v2 のコンフィグファイルを元にv3の設定していました。カスタムブートストラップ時に実行するスクリプト(postinstall.sh)の保存場所にS3バケットを引き続き指定できます。v3からコンフィグファイルの書き方が変わったため、そのまま移植はできませんでした。S3バケットの設定時に出くわしたエラーと、正しい指定方法を紹介します。

エラーメッセージ

{'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}

メッセージ全文

{
  "configurationValidationErrors": [
    {
      "level": "ERROR",
      "type": "ConfigSchemaValidator",
      "message": "[('Scheduling', {'SlurmQueues': {0: {'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}}}}, 1: {'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}}}}, 2: {'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}}}}, 3: {'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}}}}}})]"
    }
  ],
  "message": "Invalid cluster configuration."
}

結論

S3バケット名だけを指定すればよい。v2のときのままARN表記だとエラーになります。

    S3Access:
      - BucketName: blog-parallelcluster-postinstall

コンフィグを移植してみた

AWS ParallelCluster v2 から v3への設定値の読み替えドキュメントが用意されています。以下を参考にコンフィグファイルを作成します。

S3バケット

以下のS3バケットのpostinstall.shを実行するためのS3バケット設定をしていきます。

失敗例

BucketNameでS3バケット指定方法はParallelCluster v2と同じようにARN表記で指定しました。

v2仕様

s3_read_resource = arn:aws:s3:::pcluster-postinsall/*

v2ベースにv3っぽく指定

    S3Access:
      - BucketName: arn:aws:s3:::blog-parallelcluster-postinstall*

クラスター作成時に以下のエラーで作成失敗。

{'Iam': {'S3Access': {0: {'BucketName': ['String does not match expected pattern.']}

ドキュメントにはbucket_nameと書いてあります。もしかしてシンプルにバケット名だけ入力すればよい?

成功例

BucketNameにそのままS3バケット名だけ指定しました。

v3仕様

    S3Access:
      - BucketName: blog-parallelcluster-postinstall

設定の参考にコンフィグ全文記載します。

設定概要

  • マルチキューモード設定
  • スポット起動
  • プレイスメントグループ有効
  • EBS gp3指定
  • AWS Systems Manager Seesion Manager接続用ポリシー追加
  • 特定のS3バケットへ読み取り権限追加
  • カスタムブートストラップ用のスクリプト実行設定
Region: ap-northeast-1
Image:
  Os: ubuntu2004
HeadNode:
  InstanceType: m6g.large
  Networking:
    ElasticIp: true
    SubnetId: subnet-035be95eeaa091603
  Ssh:
    KeyName: sandbox-key
  LocalStorage:
    RootVolume:
      Size: 50
      Encrypted: false
      VolumeType: gp3
      Iops: 3000
      Throughput: 125
  CustomActions:
    OnNodeConfigured:
      Script: s3://blog-parallelcluster-postinstall/postinstall.sh
  Iam:
    S3Access:
      - BucketName: blog-parallelcluster-postinstall
        EnableWriteAccess: False
    AdditionalIamPolicies:
      - Policy: arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
Scheduling:
  Scheduler: slurm
  SlurmQueues:
    - Name: cpu-spot
      ComputeResources:
        - Name: c6g8xlarge
          InstanceType: c6g.8xlarge
          MinCount: 0
          MaxCount: 20
      ComputeSettings:
        LocalStorage:
          RootVolume:
            Size: 35
            Encrypted: false
            VolumeType: gp3
            Iops: 3000
            Throughput: 125
      CapacityType: SPOT
      Networking:
         SubnetIds:
           - subnet-035be95eeaa091603
         PlacementGroup:
           Enabled: true
      CustomActions:
        OnNodeConfigured:
          Script: s3://blog-parallelcluster-postinstall/postinstall.sh
      Iam:
        S3Access:
          - BucketName: blog-parallelcluster-postinstall
            EnableWriteAccess: False
        AdditionalIamPolicies:
          - Policy: arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
    - Name: high-cpu-spot
      ComputeResources:
        - Name: c6g16xlarge
          InstanceType: c6g.16xlarge
          MinCount: 0
          MaxCount: 10
      ComputeSettings:
        LocalStorage:
          RootVolume:
            Size: 35
            Encrypted: false
            VolumeType: gp3
            Iops: 3000
            Throughput: 125
      CapacityType: SPOT
      Networking:
         SubnetIds:
           - subnet-035be95eeaa091603
         PlacementGroup:
           Enabled: true
      CustomActions:
        OnNodeConfigured:
          Script: s3://blog-parallelcluster-postinstall/postinstall.sh
      Iam:
        S3Access:
          - BucketName: blog-parallelcluster-postinstall
            EnableWriteAccess: False
        AdditionalIamPolicies:
          - Policy: arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore

上記コンフィグからクラスターを作成し、エラーなく完了しました。

pcluster create-cluster --cluster-name sample-cluster --region ap-northeast-1 --cluster-configuration openfoam.yml

結果確認

IAMポリシー

ヘッドノードが作成されましたので、ヘッドノードのIAMロールを確認します。IAMロールの中にS3Accessのポリシーがありました。

内容を確認するとResource`にはS3バケット名だけ指定していたS3バケット名がARN表記に置き換わり、正しい書式でIAMポリシーが作成されていました。

S3Access

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:Get*",
                "s3:List*"
            ],
            "Resource": [
                "arn:aws:s3:::blog-parallelcluster-postinstall",
                "arn:aws:s3:::blog-parallelcluster-postinstall/*"
            ],
            "Effect": "Allow",
            "Sid": "S3Read"
        }
    ]
}

カスタムブートストラップの動作

postinstall.shではpython3.8のインストールしています。ヘッドノードの/var/log/cfn-init-cmd.logから実行時のログを確認します。最初からPython3.8がインストールされていましたが、動作していることは確認できたのでヨシとします。

/var/log/cfn-init-cmd.log

2021-09-18 01:07:47,474 P1094 [INFO] ============================================================
2021-09-18 01:07:47,474 P1094 [INFO] Command runpostinstall
2021-09-18 01:08:03,190 P1094 [INFO] -----------------------Command Output-----------------------
2021-09-18 01:08:03,190 P1094 [INFO]    Get:1 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]
2021-09-18 01:08:03,190 P1094 [INFO]    Get:2 https://fsx-lustre-client-repo.s3.amazonaws.com/ubuntu focal InRelease [3274 B]
2021-09-18 01:08:03,190 P1094 [INFO]    Get:3 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]
2021-09-18 01:08:03,190 P1094 [INFO]    Get:4 https://fsx-lustre-client-repo.s3.amazonaws.com/ubuntu focal/main arm64 Packages [9563 B]
2021-09-18 01:08:03,190 P1094 [INFO]    Get:5 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
...snip...
2021-09-18 01:08:03,191 P1094 [INFO]    Get:50 http://ap-northeast-1a.clouds.ports.ubuntu.com/ubuntu-ports focal-backports/multiverse arm64 c-n-f Metadata [116 B]
2021-09-18 01:08:03,191 P1094 [INFO]    Fetched 19.9 MB in 5s (3674 kB/s)
2021-09-18 01:08:03,191 P1094 [INFO]    Reading package lists...
2021-09-18 01:08:03,191 P1094 [INFO]    Reading package lists...
2021-09-18 01:08:03,191 P1094 [INFO]    Building dependency tree...
2021-09-18 01:08:03,191 P1094 [INFO]    Reading state information...
2021-09-18 01:08:03,191 P1094 [INFO]    python3.8 is already the newest version (3.8.10-0ubuntu1~20.04).
2021-09-18 01:08:03,191 P1094 [INFO]    python3.8 set to manually installed.
2021-09-18 01:08:03,191 P1094 [INFO]    0 upgraded, 0 newly installed, 0 to remove and 33 not upgraded.

おわりに

S3バケットと、postinstall.shの組み合わせコンピュートノードのカスタムブートストラップ(アプリケーションのインストールや、設定)を実現していました。ParallelCluster v3からはカスタムAMIがサポートされているため、もしかしたらアプリケーション、設定を焼き込んだAMIを作って運用するのが主流になるのかもしれません。まだ検証できていないため追って確認していきます。また、v2の基本であるカスタムブートストラップの動作にフォーカスして改めて検証したいと思います。