View a markdown version of this page

Example - Amazon ParallelCluster
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

This documentation references Amazon ParallelCluster. For running HPC and AI workloads, we recommend Amazon Parallel Computing Service (Amazon PCS), our managed Slurm service that lets you focus on running your workloads rather than managing infrastructure.

Example

Create a cluster

When you run the following example script, with the given inputs stored in your environment, you create a cluster. The cluster configuration is created as a Python data type based on the cluster configuration documentation.

import os import pprint import pcluster.lib as pc pp = pprint.PrettyPrinter() HEAD_NODE_SUBNET = os.environ["HEAD_NODE_SUBNET"] COMPUTE_NODE_SUBNET = os.environ["HEAD_NODE_SUBNET"] KEY_NAME = os.environ["KEY_NAME"] CONFIG = {'Image': {'Os': 'alinux2023'}, 'HeadNode': {'InstanceType': 't2.large', 'Networking': {'SubnetId': HEAD_NODE_SUBNET}, 'Ssh': {'KeyName': KEY_NAME}}, 'Scheduling': {'Scheduler': 'slurm', 'SlurmQueues': [{'Name': 'queue0', 'ComputeResources': [{'Name': 'queue0-i0', 'InstanceType': 't2.micro', 'MinCount': 0, 'MaxCount': 10}], 'Networking': {'SubnetIds': [COMPUTE_NODE_SUBNET]}}]}} pp.pprint(pc.create_cluster(cluster_name="mycluster", cluster_configuration=CONFIG))

Output:

{'cluster': {'cloudformationStackArn': 'arn:aws:cloudformation:us-east-2:123456789012:stack/mycluster/00000000-aaaa-1111-999-000000000000', 'cloudformationStackStatus': 'CREATE_IN_PROGRESS', 'clusterName': 'mycluster', 'clusterStatus': 'CREATE_IN_PROGRESS', 'region': 'us-east-2', 'scheduler': {'type': 'slurm'}, 'version': '3.16.2'}}