

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

# AWS PCS용 CloudFormation 템플릿의 일부
<a name="get-started-cfn-template-parts"></a>

CloudFormation 템플릿에는 각각 특정 목적에 맞는 섹션이 1개 이상 있습니다.는 템플릿에서 표준 형식, 구문 및 언어를 CloudFormation 정의합니다. 자세한 내용은 **AWS CloudFormation 사용 설명서의 [CloudFormation 템플릿으로 작업](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)을 참조하세요.

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

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

**Contents**
+ [헤더](#get-started-cfn-template-parts-header)
+ [Metadata](#get-started-cfn-template-parts-metadata)
+ [파라미터](#get-started-cfn-template-parts-parameters)
+ [매핑](#get-started-cfn-template-parts-mappings)
+ [리소스](#get-started-cfn-template-parts-resources)
+ [출력](#get-started-cfn-template-parts-outputs)

## 헤더
<a name="get-started-cfn-template-parts-header"></a>

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

`AWSTemplateFormatVersion`는 템플릿이 준수하는 템플릿 형식 버전을 식별합니다. 자세한 내용은 *AWS CloudFormation 사용 설명서*의 [CloudFormation 템플릿 형식 버전 구문](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html)을 참조하세요.

`Transform`는 CloudFormation이 템플릿을 처리하는 데 사용하는 매크로를 지정합니다. 자세한 내용은 *AWS CloudFormation 사용 설명서*의 [CloudFormation 템플릿 변환 섹션을](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html) 참조하세요. `AWS::Serverless-2016-10-31` 변환 CloudFormation 을 통해는 AWS Serverless Application Model (AWS SAM) 구문으로 작성된 템플릿을 처리할 수 있습니다. 자세한 내용은 *AWS CloudFormation 사용 설명서*의 [`AWS::Serverless` 변환](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-aws-serverless.html)을 참조하세요.

## Metadata
<a name="get-started-cfn-template-parts-metadata"></a>

```
### 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`.

## 파라미터
<a name="get-started-cfn-template-parts-parameters"></a>

이 `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:
         - 24.11
         - 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. Requires Slurm 24.11 or newer.

  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-_\.]+$'
```

## 매핑
<a name="get-started-cfn-template-parts-mappings"></a>

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

```
Mappings:

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

## 리소스
<a name="get-started-cfn-template-parts-resources"></a>

이 `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
        EfsFilesystemId: !GetAtt [ EfsStorage, Outputs.EFSFilesystemId ]
        FSxLustreFilesystemId: !GetAtt [ FSxLStorage, Outputs.FSxLustreFilesystemId ]
        FSxLustreFilesystemMountName: !GetAtt [ FSxLStorage, Outputs.FSxLustreMountName ]
      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 ]
```

작업 예약은를 통해 처리됩니다`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
```

## 출력
<a name="get-started-cfn-template-parts-outputs"></a>

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

```
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
```