title: How to install python 3.9 on Amazon Linux 2 with cloud-init and CDK
body: <p>I'm trying to install Python 3.9 an EC2 instance that uses Amazon Linux 2. I tried following this guide: <a href="https://computingforgeeks.com/install-latest-python-on-centos-linux/" rel="nofollow noreferrer">https://computingforgeeks.com/install-latest-python-on-centos-linux/</a>, and I was able to install Python3.9 manually on the EC2 instance by SSH'ing in and running the commands. I'm now trying to setup the EC2 instance with a UserData script that calls some CloudFormationInit scripts to install dependencies, including Python 3.9, and my script is failing.</p>
  <p>Here's part of the script that I'm using to install Python 3.9:</p>
  <pre><code>    const installPythonString = `
  #!/bin/bash
  sudo amazon-linux-extras install -y epel
  sudo yum -y update
  sudo yum groupinstall &quot;Development Tools&quot; -y
  sudo yum install openssl-devel libffi-devel bzip2-devel -y
  gcc --version
  sudo yum install wget -y
  sudo mkdir -p /opt/python3.9/
  sudo chown -R $USER:$USER /opt/python3.9/
  wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz -P /opt/python3.9
  cd /opt/python3.9/
  tar xvf Python-3.9.9.tgz
  whoami
  sudo chown -R $USER:$USER Python-3.9.9
  cd Python-3.9.9/
  ls -al
  pwd
  ./configure --enable-optimizations
  sudo make altinstall
  python3.9 --version
  pip3.9 --version
  `;
      init.addConfig('install_python39', new ec2.InitConfig([
        ec2.InitFile.fromString('/opt/install_python39.sh', installPythonString, {
          mode: '000755',
          owner: 'root',
          group: 'root',
        }),
        ec2.InitCommand.shellCommand('sudo sh install_python39.sh', {
          cwd: '/opt',
          key: 'install_python39',
        }),
  ]))
  </code></pre>
  <p>I'm getting the following errors when trying to start up the EC2 instance:</p>
  <pre><code>Python build finished successfully!
  ...
  WARNING: The script pip3.9 is installed in '/usr/local/bin' which is not on PATH.
  install_python39.sh: line 21: python3.9: command not found
  install_python39.sh: line 22: pip3.9: command not found
  </code></pre>
  <p>Is there an easier way to install Python 3.9 on Amazon Linux 2 using CloudFormationInit?</p>