Building a custom AWS ParallelCluster AMI
When using the AWS ParallelCluster command line interface (CLI) or API, you only pay for the AWS resources that are created when you create or update AWS ParallelCluster images and clusters. For more information, see AWS services used by AWS ParallelCluster.
The PCUI is built on a serverless architecture and you can use it within the AWS Free Tier category for most cases. For more information, see PCUI costs.
Important
If you build a custom AMI, you must repeat the steps that you used to create your custom AMI with each new AWS ParallelCluster release.
Before reading further, we recommend that you first review the Custom bootstrap actions section. Determine if the modifications that you want to make can be scripted and supported with future AWS ParallelCluster releases.
Even though building a custom AMI in general isn't ideal, there are specific scenarios where building a custom AMI for AWS ParallelCluster is necessary. This tutorial covers how to build a custom AMI for these scenarios.
Prerequisites
-
AWS ParallelCluster is installed.
-
The AWS CLI is installed and configured.
-
You have an Amazon EC2 key pair.
-
You have an IAM role with the permissions required to run the pcluster CLI and build images.
How to customize the AWS ParallelCluster AMI
There are two ways to build a custom AWS ParallelCluster AMI. One of these two methods is to build a new AMI using the AWS ParallelCluster CLI. Another method requires that you to make manual modifications to build a new AMI that's available under your AWS account.
Build a custom AWS ParallelCluster AMI
If you have a customized AMI and software, you can apply the changes that are needed by AWS ParallelCluster on top of it. AWS ParallelCluster relies on the EC2 Image Builder service to build customized AMIs. For more information, see the Image Builder User Guide.
Key points:
-
The process takes about 1 hour. This time can vary if there are additional Build / Components to be installed at build time.
-
The AMI is tagged with the versions of the main components. These include the kernel, scheduler, and EFA driver. A subset of the component versions are also reported in the AMI description.
-
Starting from AWS ParallelCluster 3.0.0, a new set of CLI commands can be used to manage the lifecycle of images. This includes build-image, list-images, describe-image, and delete-image.
-
This method is repeatable. You can re-run it to keep AMIs updated (for example, OS updates), and then use them when you update an existing cluster.
Note
If you use this method in the AWS China Partition, you might get network errors. For example, you might see these errors from
the pcluster build-image
command when it downloads packages from GitHub or from an OS repository. If this happens, we recommend that
you use one of the following alternative methods:
-
Follow the Modify an AWS ParallelCluster AMI approach that bypasses this command.
-
Build the image in another Partition and Region, such as
us-east-1
, and then store-restore it to move it to the China Region. For more information, see Store and restore an AMI using S3 in the Amazon EC2 User Guide.
Steps:
-
Configure your AWS account credentials so that the AWS ParallelCluster client can make calls to AWS API operations on your behalf. For a list of the required permissions, see AWS Identity and Access Management permissions in AWS ParallelCluster.
-
Create a basic build image configuration file. To do this, specify the InstanceType to be used to build the image and the ParentImage. These are used as the starting point to create the AMI. For more information about optional build parameters, see Image Configuration.
Build: InstanceType:
<BUILD_INSTANCE_TYPE>
ParentImage:<BASE_AMI_ID>
-
Use the CLI command pcluster build-image to build an AWS ParallelCluster AMI starting from the AMI that you provide as the base.
$
pcluster build-image --image-id
IMAGE_ID
--image-configurationIMAGE_CONFIG.yaml
--regionREGION
{ "image": { "imageId": "IMAGE_ID", "imageBuildStatus": "BUILD_IN_PROGRESS", "cloudformationStackStatus": "CREATE_IN_PROGRESS", "cloudformationStackArn": "arn:aws:cloudformation:us-east-1:123456789012:stack/IMAGE_ID/abcd1234-ef56-gh78-ij90-1234abcd5678", "region": "us-east-1", "version": "3.7.0" } }
Warning
pcluster build-image
uses the default VPC. If you delete the default VPC using AWS Control Tower or AWS Landing Zone, the subnet ID must be specified in the image configuration file. For more information, see SubnetId.For a list of other parameters, see the pcluster build-image command reference page. The results of the preceding command are as follows:
-
A CloudFormation stack is created based on the image configuration. The stack includes all of the EC2 Image Builder resources required for the build.
-
The created resources include the official Image Builder AWS ParallelCluster components that custom Image Builder components can be added to. To learn how to create custom components, see the Custom AMIs examples
in the HPC for Public Sector Customers Workshop. -
EC2 Image Builder launches a build instance, applies the AWS ParallelCluster cookbook, installs the AWS ParallelCluster software stack, and performs necessary configuration tasks. The AWS ParallelCluster cookbook is used to build and bootstrap AWS ParallelCluster.
-
The instance is stopped and a new AMI is created from it.
-
Another instance is launched from the newly created AMI. During the test phase, EC2 Image Builder runs tests that are defined in the Image Builder components.
-
If the build is successful, the stack is deleted. If the build fails, the stack is retained and available for inspection.
-
-
You can monitor the status of the build process by running the following command. After the build completes, you can run it to retrieve the AMI ID given in the response.
$
pcluster describe-image --image-id
IMAGE_ID
--regionREGION
# BEFORE COMPLETE { "imageConfiguration": { "url": "https://parallelcluster-1234abcd5678efgh-v1-do-not-delete.s3.amazonaws.com/parallelcluster/3.7.0/images/IMAGE_ID-abcd1234efgh5678/configs/image-config.yaml?...", }, "imageId": "IMAGE_ID", "imagebuilderImageStatus": "BUILDING", "imageBuildStatus": "BUILD_IN_PROGRESS", "cloudformationStackStatus": "CREATE_IN_PROGRESS", "cloudformationStackArn": "arn:aws:cloudformation:us-east-1:123456789012:stack/IMAGE_ID/abcd1234-ef56-gh78-ij90-1234abcd5678", "region": "us-east-1", "version": "3.7.0", "cloudformationStackTags": [ { "value": "3.7.0", "key": "parallelcluster:version" }, { "value": "IMAGE_ID", "key": "parallelcluster:image_name" }, ... ], "imageBuildLogsArn": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/imagebuilder/ParallelClusterImage-IMAGE_ID", "cloudformationStackCreationTime": "2022-04-05T21:36:26.176Z" }
# AFTER COMPLETE { "imageConfiguration": { "url": "https://parallelcluster-1234abcd5678efgh-v1-do-not-delete.s3.us-east-1.amazonaws.com/parallelcluster/3.7.0/images/IMAGE_ID-abcd1234efgh5678/configs/image-config.yaml?Signature=..." }, "imageId": "IMAGE_ID", "imageBuildStatus": "BUILD_COMPLETE", "region": "us-east-1", "ec2AmiInfo": { "amiName": "IMAGE_ID 2022-04-05T21-39-24.020Z", "amiId": "ami-1234stuv5678wxyz", "description": "AWS ParallelCluster AMI for alinux2, kernel-4.14.238-182.422.amzn2.x86_64, lustre-2.10.8-5.amzn2.x86_64, efa-1.13.0-1.amzn2.x86_64, dcv-2021.1.10598-1.el7.x86_64, slurm-20-11-8-1", "state": "AVAILABLE", "tags": [ { "value": "2021.3.11591-1.el7.x86_64", "key": "parallelcluster:dcv_version" }, ... ], "architecture": "x86_64" }, "version": "3.7.0" }
-
To create your cluster, enter the AMI ID in the CustomAmi field in your cluster configuration.
Troubleshooting and monitoring AMI creation process
Image creation completes in about an hour. You can monitor the process by running the pcluster describe-image command or log retrieval commands.
$
pcluster describe-image --image-id
IMAGE_ID
--regionREGION
The build-image command creates a CloudFormation stack with all the Amazon EC2 resources that are required to build the image, and launches the EC2 Image Builder process.
After running the build-image command, it's possible to retrieve CloudFormation stack events by using pcluster get-image-stack-events. You can filter results with the
--query
parameter to see the latest events. For more information, see Filtering AWS CLI output in the AWS Command Line Interface User Guide.
$
pcluster get-image-stack-events --image-id
IMAGE_ID
--regionREGION
--query "events[0]"{ "eventId": "ParallelClusterImage-CREATE_IN_PROGRESS-2022-04-05T21:39:24.725Z", "physicalResourceId": "arn:aws:imagebuilder:us-east-1:123456789012:image/parallelclusterimage-IMAGE_ID/3.7.0/1", "resourceStatus": "CREATE_IN_PROGRESS", "resourceStatusReason": "Resource creation Initiated", "resourceProperties": "{\"InfrastructureConfigurationArn\":\"arn:aws:imagebuilder:us-east-1:123456789012:infrastructure-configuration/parallelclusterimage-abcd1234-ef56-gh78-ij90-1234abcd5678\",\"ImageRecipeArn\":\"arn:aws:imagebuilder:us-east-1:123456789012:image-recipe/parallelclusterimage-IMAGE_ID/3.7.0\",\"DistributionConfigurationArn\":\"arn:aws:imagebuilder:us-east-1:123456789012:distribution-configuration/parallelclusterimage-abcd1234-ef56-gh78-ij90-1234abcd5678\",\"Tags\":{\"parallelcluster:image_name\":\"IMAGE_ID\",\"parallelcluster:image_id\":\"IMAGE_ID\"}}", "stackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/IMAGE_ID/abcd1234-ef56-gh78-ij90-1234abcd5678", "stackName": "IMAGE_ID", "logicalResourceId": "ParallelClusterImage", "resourceType": "AWS::ImageBuilder::Image", "timestamp": "2022-04-05T21:39:24.725Z" }
After about 15 minutes, the stack events appear in the log event entry related to Image Builder creation. You can now list image log streams and monitor the Image Builder steps by using pcluster list-image-log-streams and pcluster get-image-log-events commands.
$
pcluster list-image-log-streams --image-id
"3.7.0/1" ]IMAGE_ID
--regionREGION
\ --query 'logStreams[*].logStreamName'$
pcluster get-image-log-events --image-id
IMAGE_ID
--regionREGION
\ --log-stream-name 3.7.0/1 --limit 3{ "nextToken": "f/36295977202298886557255241372854078762600452615936671762", "prevToken": "b/36295977196879805474012299949460899222346900769983430672", "events": [ { "message": "ExecuteBash: FINISHED EXECUTION", "timestamp": "2022-04-05T22:13:26.633Z" }, { "message": "Document arn:aws:imagebuilder:us-east-1:123456789012:component/parallelclusterimage-test-abcd1234-ef56-gh78-ij90-1234abcd5678/3.7.0/1", "timestamp": "2022-04-05T22:13:26.741Z" }, { "message": "TOE has completed execution successfully", "timestamp": "2022-04-05T22:13:26.819Z" } ] }
Continue to check with the describe-image command until you see the BUILD_COMPLETE
status.
$
pcluster describe-image --image-id
IMAGE_ID
--regionREGION
{ "imageConfiguration": { "url": "https://parallelcluster-1234abcd5678efgh-v1-do-not-delete.s3.us-east-1.amazonaws.com/parallelcluster/3.7.0/images/IMAGE_ID-abcd1234efgh5678/configs/image-config.yaml?Signature=..." }, "imageId": "IMAGE_ID", "imageBuildStatus": "BUILD_COMPLETE", "region": "us-east-1", "ec2AmiInfo": { "amiName": "IMAGE_ID 2022-04-05T21-39-24.020Z", "amiId": "ami-1234stuv5678wxyz", "description": "AWS ParallelCluster AMI for alinux2, kernel-4.14.238-182.422.amzn2.x86_64, lustre-2.10.8-5.amzn2.x86_64, efa-1.13.0-1.amzn2.x86_64, dcv-2021.1.10598-1.el7.x86_64, slurm-20-11-8-1", "state": "AVAILABLE", "tags": [ { "value": "2021.3.11591-1.el7.x86_64", "key": "parallelcluster:dcv_version" }, ... ], "architecture": "x86_64" }, "version": "3.7.0" }
If you need to troubleshoot a custom AMI creation issue, create an archive of the image logs as described in following steps.
It's possible to archive the logs in an Amazon S3 bucket or in a local file, depending on the --output
parameter.
$
pcluster export-image-logs --image-id
IMAGE_ID
--regionREGION
\ --bucketBUCKET_NAME
--bucket-prefixBUCKET_FOLDER
{ "url": "https://BUCKET_NAME.s3.us-east-1.amazonaws.com/BUCKET-FOLDER/IMAGE_ID-logs-202209071136.tar.gz?AWSAccessKeyId=..." }
$
pcluster export-image-logs --image-id
IMAGE_ID
\ --regionREGION
--bucketBUCKET_NAME
--bucket-prefixBUCKET_FOLDER
--output-file /tmp/archive.tar.gz{ "path": "/tmp/archive.tar.gz" }
The archive contains the CloudWatch Logs Streams related to the Image Builder process and AWS CloudFormation stack events. The command might take several minutes to run.
Managing Custom AMIs
Starting from AWS ParallelCluster 3.0.0, a new set of commands has been added in the CLI to build, monitor, and manage the image lifecycle. For more information about the commands, see pcluster commands.
Modify an AWS ParallelCluster AMI
This method consists of modifying an official AWS ParallelCluster AMI by adding customization on top of it. The base AWS ParallelCluster AMIs are updated with new releases. These AMIs have all of the components that are required for AWS ParallelCluster to function when it's installed and configured. You can start with one of these as your base.
Key points:
-
This method is faster than the build-image command. However, it's a manual process and not automatically repeatable.
-
With this method, you don't have access to the log retrieval and image lifecycle management commands that are available through the CLI.
Steps: