View a markdown version of this page

AWS PCS용 CloudFormation 템플릿의 일부 - AWS PCS

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS PCS용 CloudFormation 템플릿의 일부

CloudFormation 템플릿에는 각각 특정 목적에 맞는 섹션이 1개 이상 있습니다.는 템플릿에서 표준 형식, 구문 및 언어를 CloudFormation 정의합니다. 자세한 내용은 AWS CloudFormation 사용 설명서의 CloudFormation 템플릿으로 작업을 참조하세요.

CloudFormation 템플릿은 사용자 지정이 가능하므로 형식이 다를 수 있습니다. CloudFormation 템플릿에서 AWS PCS 클러스터를 생성하는 데 필요한 부분을 이해하려면 제공된 샘플 템플릿을 검토하여 샘플 클러스터를 생성하는 것이 좋습니다. 이 주제에서는 해당 샘플 템플릿의 섹션을 간략하게 설명합니다.

중요

이 주제의 코드 샘플은 완료되지 않았습니다. 줄임표([...])가 있으면 표시되지 않는 추가 코드가 있음을 나타냅니다. 전체 YAML 형식의 CloudFormation 템플릿을 다운로드하려면 섹션을 참조하세요CloudFormation 샘플 AWS PCS 클러스터를 생성하기 위한 템플릿.

헤더

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: AWS Parallel Computing Service "getting started" cluster

AWSTemplateFormatVersion는 템플릿이 준수하는 템플릿 형식 버전을 식별합니다. 자세한 내용은 AWS CloudFormation 사용 설명서CloudFormation 템플릿 형식 버전 구문을 참조하세요.

Transform는 CloudFormation이 템플릿을 처리하는 데 사용하는 매크로를 지정합니다. 자세한 내용은 AWS CloudFormation 사용 설명서CloudFormation 템플릿 변환 섹션을 참조하세요. AWS::Serverless-2016-10-31 변환 CloudFormation 을 통해는 AWS Serverless Application Model (AWS SAM) 구문으로 작성된 템플릿을 처리할 수 있습니다. 자세한 내용은 AWS CloudFormation 사용 설명서AWS::Serverless 변환을 참조하세요.

Metadata

### Stack metadata Metadata: AWS::CloudFormation::Interface: ParameterGroups: - Label: default: PCS Cluster configuration Parameters: - SlurmVersion - ManagedAccounting - AccountingPolicyEnforcement - Label: default: PCS ComputeNodeGroups configuration Parameters: - NodeArchitecture - KeyName - ClientIpCidr - Label: default: HPC Recipes configuration Parameters: - HpcRecipesS3Bucket - HpcRecipesBranch

CloudFormation 템플릿의 metadata 섹션에서는 템플릿 자체에 대한 정보를 제공합니다. 샘플 템플릿은 AWS PCS를 사용하는 완전한 고성능 컴퓨팅(HPC) 클러스터를 생성합니다. 샘플 템플릿의 메타데이터 섹션은가 해당 스택을 CloudFormation 시작(프로비저닝)하는 방법을 제어하는 파라미터를 선언합니다. 아키텍처 선택(NodeArchitecture), Slurm 버전() 및 액세스 제어KeyName( 및 SlurmVersion)를 제어하는 파라미터가 있습니다ClientIpCidr.

파라미터

Parameters 섹션에서는 템플릿의 사용자 지정 파라미터를 정의합니다.는 이러한 파라미터 정의를 CloudFormation 사용하여이 템플릿에서 스택을 시작할 때 상호 작용하는 양식을 구성하고 검증합니다.

Parameters: NodeArchitecture: Type: String Default: x86 AllowedValues: - x86 - Graviton Description: Processor architecture for the login and compute node instances SlurmVersion: Type: String Default: 25.11 Description: Version of Slurm to use AllowedValues: - 25.05 - 25.11 ManagedAccounting: Type: String Default: 'disabled' AllowedValues: - 'enabled' - 'disabled' Description: Monitor cluster usage, manage access control, and enforce resource limits with Slurm accounting. AccountingPolicyEnforcement: Description: Specify which Slurm accounting policies to enforce Type: String Default: none AllowedValues: - none - 'associations,limits,safe' KeyName: Description: SSH keypair to log in to the head node Type: AWS::EC2::KeyPair::KeyName AllowedPattern: ".+" # Required ClientIpCidr: Description: IP(s) allowed to access the login node over SSH. We recommend that you restrict it with your own IP/subnet (x.x.x.x/32 for your own ip or x.x.x.x/24 for range. Replace x.x.x.x with your own PUBLIC IP. You can get your public IP using tools such as https://ifconfig.co/) Default: 127.0.0.1/32 Type: String AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) ConstraintDescription: Value must be a valid IP or network range of the form x.x.x.x/x. HpcRecipesS3Bucket: Type: String Default: aws-hpc-recipes Description: HPC Recipes for AWS S3 bucket AllowedValues: - aws-hpc-recipes - aws-hpc-recipes-dev HpcRecipesBranch: Type: String Default: main Description: HPC Recipes for AWS release branch AllowedPattern: '^(?!.*/\.git$)(?!.*/\.)(?!.*\\.\.)[a-zA-Z0-9-_\.]+$'

매핑

Mappings 섹션에서는 특정 조건 또는 종속성을 기반으로 값을 지정하는 키-값 페어를 정의합니다.

Mappings: Architecture: AmiArchParameter: Graviton: arm64 x86: x86_64 LoginNodeInstances: Graviton: c7g.xlarge x86: c6i.xlarge ComputeNodeInstances: Graviton: c7g.xlarge x86: c6i.xlarge

리소스

Resources 섹션에서는 스택의 일부로 프로비저닝하고 구성할 AWS 리소스를 선언합니다.

Resources: [...]

템플릿은 샘플 클러스터 인프라를 계층으로 프로비저닝합니다. VPC 구성Networking의 경우 로 시작합니다. 스토리지는 공유 스토리지용 및 FSxLStorage 고성능 스토리지EfsStorage용 이중 시스템에서 제공합니다. 코어 클러스터는를 통해 설정됩니다PCSCluster.

Networking: Type: AWS::CloudFormation::Stack Properties: Parameters: ProvisionSubnetsC: "False" TemplateURL: !Sub 'https://${HpcRecipesS3Bucket}.s3.amazonaws.com/${HpcRecipesBranch}/recipes/net/hpc_large_scale/assets/main.yaml' EfsStorage: Type: AWS::CloudFormation::Stack Properties: Parameters: SubnetIds: !GetAtt [ Networking, Outputs.DefaultPrivateSubnet ] SubnetCount: 1 VpcId: !GetAtt [ Networking, Outputs.VPC ] TemplateURL: !Sub 'https://${HpcRecipesS3Bucket}.s3.amazonaws.com/${HpcRecipesBranch}/recipes/storage/efs_simple/assets/main.yaml' FSxLStorage: Type: AWS::CloudFormation::Stack Properties: Parameters: PerUnitStorageThroughput: 125 SubnetId: !GetAtt [ Networking, Outputs.DefaultPrivateSubnet ] VpcId: !GetAtt [ Networking, Outputs.VPC ] TemplateURL: !Sub 'https://${HpcRecipesS3Bucket}.s3.amazonaws.com/${HpcRecipesBranch}/recipes/storage/fsx_lustre/assets/persistent.yaml' [...] # Cluster PCSCluster: Type: AWS::PCS::Cluster Properties: Name: !Sub '${AWS::StackName}' Size: SMALL Scheduler: Type: SLURM Version: !Ref SlurmVersion Networking: SubnetIds: - !GetAtt [ Networking, Outputs.DefaultPrivateSubnet ] SecurityGroupIds: - !GetAtt [ PCSSecurityGroup, Outputs.ClusterSecurityGroupId ]

컴퓨팅 리소스의 경우 템플릿은 단일 로그인 노드의 PCSNodeGroupLogin 경우 , 최대 4개의 컴퓨팅 노드PCSNodeGroupCompute의 경우 라는 두 개의 노드 그룹을 생성합니다. 이러한 노드 그룹은 권한 및 인스턴스 구성PCSInstanceProfile에 대해 PCSLaunchTemplate에서 지원됩니다.

# Compute Node groups PCSInstanceProfile: Type: AWS::CloudFormation::Stack Properties: Parameters: # We have to regionalize this in case CX use the template in more than one region. Otherwise, # the create action will fail since instance-role-${AWS::StackName} already exists! RoleName: !Sub '${AWS::StackName}-${AWS::Region}' TemplateURL: !Sub 'https://${HpcRecipesS3Bucket}.s3.amazonaws.com/${HpcRecipesBranch}/recipes/pcs/getting_started/assets/pcs-iip-minimal.yaml' PCSLaunchTemplate: Type: AWS::CloudFormation::Stack Properties: Parameters: VpcDefaultSecurityGroupId: !GetAtt [ Networking, Outputs.SecurityGroup ] ClusterSecurityGroupId: !GetAtt [ PCSSecurityGroup, Outputs.ClusterSecurityGroupId ] SshSecurityGroupId: !GetAtt [ PCSSecurityGroup, Outputs.InboundSshSecurityGroupId ] EfsFilesystemSecurityGroupId: !GetAtt [ EfsStorage, Outputs.SecurityGroupId ] FSxLustreFilesystemSecurityGroupId: !GetAtt [ FSxLStorage, Outputs.FSxLustreSecurityGroupId ] SshKeyName: !Ref KeyName TemplateURL: !Sub 'https://${HpcRecipesS3Bucket}.s3.amazonaws.com/${HpcRecipesBranch}/recipes/pcs/getting_started/assets/cfn-pcs-lt-efs-fsxl.yaml' # Compute Node groups - Login Nodes PCSNodeGroupLogin: Type: AWS::PCS::ComputeNodeGroup Properties: ClusterId: !GetAtt [PCSCluster, Id] Name: login ScalingConfiguration: MinInstanceCount: 1 MaxInstanceCount: 1 IamInstanceProfileArn: !GetAtt [ PCSInstanceProfile, Outputs.InstanceProfileArn ] CustomLaunchTemplate: TemplateId: !GetAtt [ PCSLaunchTemplate, Outputs.LoginLaunchTemplateId ] Version: 1 SubnetIds: - !GetAtt [ Networking, Outputs.DefaultPublicSubnet ] AmiId: !GetAtt [PcsSampleAmi, AmiId] InstanceConfigs: - InstanceType: !FindInMap [ Architecture, LoginNodeInstances, !Ref NodeArchitecture ] # Compute Node groups - Compute Nodes PCSNodeGroupCompute: Type: AWS::PCS::ComputeNodeGroup Properties: ClusterId: !GetAtt [PCSCluster, Id] Name: compute-1 ScalingConfiguration: MinInstanceCount: 0 MaxInstanceCount: 4 IamInstanceProfileArn: !GetAtt [ PCSInstanceProfile, Outputs.InstanceProfileArn ] CustomLaunchTemplate: TemplateId: !GetAtt [ PCSLaunchTemplate, Outputs.ComputeLaunchTemplateId ] Version: 1 SubnetIds: - !GetAtt [ Networking, Outputs.DefaultPrivateSubnet ] AmiId: !GetAtt [PcsSampleAmi, AmiId] InstanceConfigs: - InstanceType: !FindInMap [ Architecture, ComputeNodeInstances, !Ref NodeArchitecture ]

두 노드 그룹 모두 공유 스토리지를 탑재하고 노드 로그를 nodeBootstrapped 단계에서 Amazon CloudWatch Logs로 전달하는 NodeLifecycleActions 블록을 포함합니다. 이는 시작 템플릿 사용자 데이터를 통해 파일 시스템을 탑재하는 이전 접근 방식을 대체합니다. Amazon EFS는 사용자 홈 디렉터리/home를 위해에 탑재되고 FSx for Lustre는 고성능 스크래치 스토리지를 /shared 위해에 탑재됩니다. 네 번째 작업은 노드 수명 주기 작업 로그를 Amazon CloudWatch Logs로 전달합니다. 탑재 및 디렉터리 작업은 EVERY_BOOT를 사용하여 재부팅할 때마다 실행되고 스토리지configure-cloudwatch-logs를 계속 사용할 수 있도록 하는 반면, CloudWatch 에이전트 구성은 재부팅 후에도 유지FIRST_BOOT_ONLY되므로 다시 적용할 필요가 없습니다. 노드 수명 주기 작업에 대한 자세한 내용은 섹션을 참조하세요노드 수명 주기 작업. 에서 AWS 유지 관리하는 스크립트에 대한 자세한 내용은 섹션을 참조하세요AWS유지 관리형 스크립트.

NodeLifecycleActions: ScriptCachingPolicy: CACHE_ONCE Stages: NodeBootstrapped: # Forward node lifecycle action logs to CloudWatch Logs. Runs first so the # actions that follow have their output captured from the node's first boot. - Name: configure-cloudwatch-logs ScriptSource: ScriptLocation: !Sub 's3://aws-pcs-repo-${AWS::Region}/aws-pcs-node-lifecycle-scripts/configure-cloudwatch-logs-v1-latest.sh' OnError: CONTINUE ExecutionPolicy: FIRST_BOOT_ONLY # Mount EFS as the home-directory base at /home and create home dirs on first login. - Name: configure-efs-homes ScriptSource: ScriptLocation: !Sub 's3://aws-pcs-repo-${AWS::Region}/aws-pcs-node-lifecycle-scripts/configure-efs-homes-v1-latest.sh' Arguments: - '--efs-id' - !GetAtt [ EfsStorage, Outputs.EFSFilesystemId ] - '--home-base' - '/home' - '--options' - 'tls' OnError: CONTINUE ExecutionPolicy: EVERY_BOOT # Mount FSx for Lustre at /shared for high-performance shared scratch storage. - Name: mount-fsx-lustre ScriptSource: ScriptLocation: !Sub 's3://aws-pcs-repo-${AWS::Region}/aws-pcs-node-lifecycle-scripts/mount-fsx-lustre-v1-latest.sh' Arguments: - '--fsx-dns-name' - !GetAtt FSxLustreLookup.DNSName - '--mount-name' - !GetAtt FSxLustreLookup.MountName - '--mount-point' - '/shared' OnError: CONTINUE ExecutionPolicy: EVERY_BOOT # Set /shared to world-writable sticky mode (1777). Runs after mount-fsx-lustre # so it applies to the mounted file system, not an empty directory. - Name: set-shared-dir-mode ScriptSource: ScriptLocation: !Sub 'https://${HpcRecipesS3Bucket}.s3.us-east-1.amazonaws.com/${HpcRecipesBranch}/recipes/pcs-scripts/open_shared_dir/assets/set-shared-dir-mode-v1.0.0.sh' Arguments: - '--path' - '/shared' - '--mode' - '1777' OnError: CONTINUE ExecutionPolicy: EVERY_BOOT

작업 예약은를 통해 처리됩니다PCSQueueCompute.

PCSQueueCompute: Type: AWS::PCS::Queue Properties: ClusterId: !GetAtt [PCSCluster, Id] Name: demo ComputeNodeGroupConfigurations: - ComputeNodeGroupId: !GetAtt [PCSNodeGroupCompute, Id]

AMI 선택은 PcsAMILookupFn Lambda 함수 및 관련 리소스를 통해 자동으로 수행됩니다.

PcsAMILookupRole: Type: AWS::IAM::Role [...] PcsAMILookupFn: Type: AWS::Lambda::Function Properties: Runtime: python3.12 Handler: index.handler Role: !GetAtt PcsAMILookupRole.Arn Code: [...] Timeout: 30 MemorySize: 128 # Example of using the custom resource to look up an AMI PcsSampleAmi: Type: Custom::AMILookup Properties: ServiceToken: !GetAtt PcsAMILookupFn.Arn OperatingSystem: 'amzn2' Architecture: !FindInMap [ Architecture, AmiArchParameter, !Ref NodeArchitecture ] SlurmVersion: !Ref SlurmVersion

출력

템플릿은 ClusterId, 및를 통해 클러스터 식별 PcsConsoleUrl및 관리 URLsEc2ConsoleUrl.

Outputs: ClusterId: Description: The Id of the PCS cluster Value: !GetAtt [ PCSCluster, Id ] PcsConsoleUrl: Description: URL to access the cluster in the PCS console Value: !Sub - https://${ConsoleDomain}/pcs/home?region=${AWS::Region}#/clusters/${ClusterId} - { ConsoleDomain: !If [ GovCloud, 'console.amazonaws-us-gov.com', !If [ China, 'console.amazonaws.cn', !Sub '${AWS::Region}.console.aws.amazon.com']], ClusterId: !GetAtt [ PCSCluster, Id ] } Export: Name: !Sub ${AWS::StackName}-PcsConsoleUrl Ec2ConsoleUrl: Description: URL to access instance(s) in the login node group via Session Manager Value: !Sub - https://${ConsoleDomain}/ec2/home?region=${AWS::Region}#Instances:instanceState=running;tag:aws:pcs:compute-node-group-id=${NodeGroupLoginId} - { ConsoleDomain: !If [ GovCloud, 'console.amazonaws-us-gov.com', !If [ China, 'console.amazonaws.cn', !Sub '${AWS::Region}.console.aws.amazon.com']], NodeGroupLoginId: !GetAtt [ PCSNodeGroupLogin, Id ] } Export: Name: !Sub ${AWS::StackName}-Ec2ConsoleUrl