View a markdown version of this page

Teile einer CloudFormation Vorlage für AWS 5 STCK - AWS STCK

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Teile einer CloudFormation Vorlage für AWS 5 STCK

Eine CloudFormation Vorlage besteht aus einem oder mehreren Abschnitten, die jeweils einem bestimmten Zweck dienen. CloudFormation definiert Standardformat, Syntax und Sprache in einer Vorlage. Weitere Informationen finden Sie im AWS CloudFormation Benutzerhandbuch unter Arbeiten mit CloudFormation Vorlagen.

CloudFormation Vorlagen sind in hohem Maße anpassbar und daher können ihre Formate variieren. Um die für die Erstellung eines AWS PCS-Clusters erforderlichen Teile einer CloudFormation Vorlage zu verstehen, empfehlen wir Ihnen, sich die Beispielvorlage anzusehen, die wir für die Erstellung eines Beispielclusters bereitstellen. In diesem Thema werden die Abschnitte dieser Beispielvorlage kurz erläutert.

Wichtig

Die Codebeispiele in diesem Thema sind nicht vollständig. Das Vorhandensein von Auslassungspunkten ([...]) weist darauf hin, dass zusätzlicher Code vorhanden ist, der nicht angezeigt wird. Informationen zum Herunterladen der vollständigen YAML-formatted CloudFormation Vorlage finden Sie unterCloudFormation Vorlagen zum Erstellen einer Probe AWS PCS-Cluster.

Header

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

AWSTemplateFormatVersionidentifiziert die Version des Vorlagenformats, der die Vorlage entspricht. Weitere Informationen finden Sie im AWS CloudFormation Benutzerhandbuch unter Syntax der Version des CloudFormation Vorlagenformats.

Transformgibt ein Makro an, das zur Verarbeitung der Vorlage CloudFormation verwendet wird. Weitere Informationen finden Sie im Abschnitt zum Transformieren von CloudFormation Vorlagen im AWS CloudFormation Benutzerhandbuch. Die AWS::Serverless-2016-10-31 Transformation ermöglicht CloudFormation die Verarbeitung einer in der AWS Serverless Application Model (AWS SAM) -Syntax geschriebenen Vorlage. Weitere Informationen finden Sie unter AWS::Serverless transform im AWS CloudFormation Benutzerhandbuch.

Metadaten

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

Der metadata Abschnitt einer CloudFormation Vorlage enthält Informationen über die Vorlage selbst. Mit der Beispielvorlage wird ein vollständiger HPC-Cluster (High Performance Computing) erstellt, der AWS PCS verwendet. Im Metadatenbereich der Beispielvorlage werden Parameter deklariert, die steuern, wie der entsprechende CloudFormation Stack gestartet (bereitgestellt) wird. Es gibt Parameter, die die Architekturauswahl (NodeArchitecture), die Slurm-Version (SlurmVersion) und die Zugriffskontrollen (KeyNameandClientIpCidr) steuern.

Parameters

Der Parameters Abschnitt definiert die benutzerdefinierten Parameter für die Vorlage. CloudFormation verwendet diese Parameterdefinitionen, um das Formular zu erstellen und zu validieren, mit dem Sie interagieren, wenn Sie einen Stapel von dieser Vorlage aus starten.

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

Der Mappings Abschnitt definiert Schlüssel-Wert-Paare, die Werte angeben, die auf bestimmten Bedingungen oder Abhängigkeiten basieren.

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

Ressourcen

Der Resources Abschnitt deklariert die AWS Ressourcen, die bereitgestellt und konfiguriert werden müssen, als Teil des Stacks.

Resources: [...]

Die Vorlage stellt die Beispiel-Cluster-Infrastruktur in Schichten bereit. Sie beginnt mit „NetworkingFür die VPC-Konfiguration“. Der Speicher wird von zwei Systemen bereitgestellt: EfsStorage für gemeinsam genutzten Speicher und FSxLStorage für Hochleistungsspeicher. Der Core-Cluster wird eingerichtet durchPCSCluster.

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 ]

Für Rechenressourcen erstellt die Vorlage zwei Knotengruppen: PCSNodeGroupLogin für einen einzelnen Anmeldeknoten und PCSNodeGroupCompute für bis zu vier Rechenknoten. Diese Knotengruppen werden von PCSInstanceProfile für Berechtigungen und PCSLaunchTemplate für Instanzkonfigurationen unterstützt.

# 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 ]

Beide Knotengruppen enthalten einen NodeLifecycleActions Block, der gemeinsam genutzten Speicher bereitstellt und Knotenprotokolle in der Phase an Amazon CloudWatch Logs weiterleitet. nodeBootstrapped Dies ersetzt den älteren Ansatz, Dateisysteme mithilfe von Launch-Template-Benutzerdaten einzubinden. Amazon EFS ist /home für Benutzerstartverzeichnisse gemountet, und FSx for Lustre ist für Hochleistungs-Scratch-Speicher gemountet/shared. Eine vierte Aktion leitet die Aktionsprotokolle des Knotenlebenszyklus an Amazon Logs weiter. CloudWatch Die Mount- und Directory-Aktionen werden verwendet, EVERY_BOOT sodass sie bei jedem Neustart ausgeführt werden und Speicherplatz verfügbar bleibt, während sie configure-cloudwatch-logs verwendet werden, FIRST_BOOT_ONLY weil die CloudWatch Agentenkonfiguration auch nach Neustarts erhalten bleibt und nicht erneut angewendet werden muss. Weitere Informationen zu Aktionen im Lebenszyklus von Knoten finden Sie unter. Aktionen im Lebenszyklus eines Knotens Einzelheiten zu den Skripten, die AWS verwaltet werden, finden Sie unterAWS-gepflegte Skripte.

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

Die Auftragsplanung wird über abgewickeltPCSQueueCompute.

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

Die AMI-Auswahl erfolgt automatisch über die PcsAMILookupFn Lambda-Funktion und die zugehörigen Ressourcen.

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

Outputs

Die Vorlage gibt Cluster-Identifikations- und Verwaltungs-URLs über ClusterIdPcsConsoleUrl, und Ec2ConsoleUrl aus.

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