Amazon ParallelCluster Python library API
Starting with Amazon ParallelCluster version 3.5.0, you can access Amazon ParallelCluster with the Amazon ParallelCluster Python library. You can access the
Amazon ParallelCluster library in your pcluster
environment or from within an Amazon Lambda runtime. Learn how to access the Amazon ParallelCluster
API by using the Amazon ParallelCluster Python library. The Amazon ParallelCluster Python library offers the same functionality that the Amazon ParallelCluster API
delivers.
The Amazon ParallelCluster Python library operations and parameters mirror those of the API parameters when converted to snake_case
with no capital
letters.
Topics
Amazon ParallelCluster Python library authorization
Specify credentials by using any of the standard ways that are valid for boto3. For more information,
see the boto3 documentation
Install the Amazon ParallelCluster Python library
-
Install
pcluster
CLI version 3.5.0 or later by following the instructions given in Setting up Amazon ParallelCluster. -
Import the
pcluster
module and start using the library, as shown in the following example:import pcluster.lib as
pc
pc.create_cluster(cluster_name="mycluster"
, cluster_configuration="config.yaml"
Amazon Lambda for the Amazon ParallelCluster Python library
You can deploy a Lambda layer and runtime to access to the Amazon ParallelCluster Python library. We host Amazon ParallelCluster zip files that you can use by entering the link to the zip file as described in the following steps. Lambda uses the zip files to prepare the runtime environment to support access to the Python library. The Amazon ParallelCluster Python library is added with Amazon ParallelCluster version 3.5.0. You can only use the library for versions 3.5.0 and later.
The hosted zip file URL is in the format: s3://
aws-region-id
-aws-parallelcluster/parallelcluster/3.7.0
/layers/aws-parallelcluster/lambda-layer.zip
Get started accessing the Amazon ParallelCluster Python library with Amazon Lambda
Create a Lambda layer
-
Log in to the Amazon Web Services Management Console and navigate to the Amazon Lambda console.
-
In the navigation pane, select Layers, then Create layer.
-
Enter a name for your layer and select Upload a file from Amazon S3.
-
Enter the URL to the zip file: s3://
aws-region-id
-aws-parallelcluster/parallelcluster/3.7.0
/layers/aws-parallelcluster/lambda-layer.zip. -
For Compatible architectures, choose the x86_64 architecture.
-
For Compatible runtimes, choose the Python 3.9 runtime.
-
Choose Create.
Use your Lambda layer
-
In the Lambda console navigation pane, select Functions, then Create function.
-
Enter a name for your function.
-
For Runtime, choose the Python 3.9 runtime.
-
For Architecture, choose the x86_64 architecture.
-
Choose Create function.
-
After the function is created, choose Layers and select Add a layer.
-
Select Custom layers and choose the layer you created in previous steps.
-
Choose the layer version.
-
Choose Add.
-
Your Lambda needs permissions to manage clusters created with Amazon ParallelCluster. Create a Lambda role with the permissions listed in Base Amazon ParallelCluster pcluster user policy.
You can now access Amazon ParallelCluster from the Python library as described in Amazon ParallelCluster Python library API.