Skip to content

(3.0.2, 2.11.3 and earlier) Custom AMI creation (pcluster build image or createami) fails for centos7 and ubuntu1804

Hanwen edited this page Jan 20, 2022 · 3 revisions

The issue

Note: As a 2022-01-20, the issue has been fix. Users do not need any further actions.

On 2021-03-04 version 0.6.0 of the pystache python package was released. This package is a dependency of the aws-cfn-bootstrap package, which contains the AWS CloudFormation helper scripts. The new version of the pystache package dropped support for python 2.x, causing the installation of the aws-cfn-bootstrap package to fail when occurring as part of the pcluster build-image (ParallelCluster 3.x) or pcluster createami (ParallelCluster 2.x) commands. This issue does not affect AMIs which already have the aforementioned packages installed.

Affected ParallelCluster versions

This issue affects all versions of ParallelCluster up to v3.0.2 and v2.11.3 when the selected OS is CentOS 7 or Ubuntu 18.

Error details

When building AMIs via the pcluster build-image or pcluster createami commands the process fails with the following error message, that can be found in the build log:

curl --retry 3 -L -o /tmp/aws-cfn-bootstrap-latest.tar.gz https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
pip install /tmp/aws-cfn-bootstrap-latest.tar.gz

File "/tmp/pip-build-im3UcQ/pystache/setup.py", line 183
command = f"pandoc -f markdown-smart --write=rst --output={rst_temp_path} {md_path}"
SyntaxError: invalid syntax

Note

  • for ParallelCluster 3.x the build log events can be retrieved using the command pcluster get-image-log-events
  • for ParallelCluster 2.x the build log file path (packer log) is printed by the pcluster createami command

The workaround

v3.0.2

For v3.0.2 the workaround is to patch the ParallelCluster ImageBuilder Component using the provided script

  1. create a script named patch_pcluster.sh with the following content:
#!/bin/bash
PCLUSTER_MAIN_COMPONENT_FILE="$(find "$(dirname $(which pcluster))/../" -name "parallelcluster.yaml")"
echo "Found PCluster main component file at (${PCLUSTER_MAIN_COMPONENT_FILE})."
echo "Backing up original file to ${PCLUSTER_MAIN_COMPONENT_FILE}.BAK"
cp "${PCLUSTER_MAIN_COMPONENT_FILE}" "${PCLUSTER_MAIN_COMPONENT_FILE}.BAK"
echo "Patching it..."
sed -i 's/"pip2"/"pip3"/g' "${PCLUSTER_MAIN_COMPONENT_FILE}"
sed -i 's/"pip"/"pip3"/g' "${PCLUSTER_MAIN_COMPONENT_FILE}"
sed -i 's/aws-cfn-bootstrap-latest.tar.gz/aws-cfn-bootstrap-py3-latest.tar.gz/g' "${PCLUSTER_MAIN_COMPONENT_FILE}"
echo "Patch done. You can now start build AMI process with 'pcluster build-image' command"
  1. make the script executable and execute it
chmod +x patch_pcluster.sh
./patch_pcluster.sh

You can now use the pcluster build-image command to create a custom AMI. For example, create the following build configuration file build.yaml:

Region: eu-south-1
Build:
  ParentImage: ${BASE_AMI_ID}
  InstanceType: c5.12xlarge

And run the following command to create the image:

pcluster build-image --image-id fixed-centos7 --image-configuration build.yaml --region ${AWS_REGION}

v2.11.3

For v2.11.3 the workaround is to use the archive of a patched cookbook that can be found here. This cookbook contains the contents of the release-2.11 branch up plus the fix commit. It can be used as the value passed to the -cc argument of the pcluster createami command:

pcluster createami -ai ${BASE_AMI_ID} -os ${BASE_AMI_OS} \
  -cc https://us-east-1-aws-parallelcluster.s3.amazonaws.com/patches/2.11.3/aws-parallelcluster-cookbook-2.11.3.tgz
Clone this wiki locally