[AWS] Cloud9で、Python3.8をインストールする方法

# Cloud9のPython
2021年3月時点では、Cloud9（というかAmazon Linux2）に標準で入っているPythonは、3.79です。

```bash
Admin:~/environment $ python -V
Python 3.7.9
```

# SAMでLamdaを書くぞ
SAMでLamdaのコードを書く際に、Runtimeとして、Python3.8を選択できます。
が、インストールされているPythonのバージョンがあっていないため、酷くお叱りを受けます。

```bash
Admin:~/environment/sam-app $ sam build
Building codeuri: hello_world/ runtime: python3.8 metadata: {} functions: ['HelloWorldFunction']

Build Failed
Error: PythonPipBuilder:Validation - Binary validation failed for python, searched for python in following locations  : ['/usr/bin/python'] which did not satisfy constraints for runtime: python3.8. Do you have python for runtime: python3.8 on your PATH?
```

# Cloud9でPython3.8インストール
セオリー通りに、インストールしようとしますが、残念ながらうまくいきません。

```bash
Admin:~/environment/sam-app $ sudo yum install python38
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
229 packages excluded due to repository priority protections
No package python38 available.
Error: Nothing to do


python38 is available in Amazon Linux Extra topic "python3.8"

To use, run
# sudo amazon-linux-extras install python3.8

Learn more at
https://aws.amazon.com/amazon-linux-2/faqs/#Amazon_Linux_Extras
```

そんなパッケージないと叱られます。
が、ちゃんとヒントが書いてあるので、その通りコマンドを叩きます。

```bash
Admin:~/environment/sam-app $ sudo amazon-linux-extras install python3.8
Installing python38
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel amzn2extra-lamp-mariadb10.2-php7.2 amzn2extra-python3.8 epel hashicorp
33 metadata files removed
11 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                                            | 3.7 kB  00:00:00     
amzn2extra-docker                                                                                                                     | 3.0 kB  00:00:00     
amzn2extra-epel                                                                                                                       | 3.0 kB  00:00:00     
amzn2extra-lamp-mariadb10.2-php7.2                                                                                                    | 3.0 kB  00:00:00     
amzn2extra-python3.8                                                                                                                  | 3.0 kB  00:00:00     
epel/x86_64/metalink                                                                                                                  | 5.1 kB  00:00:00     
epel                                                                                                                                  | 4.7 kB  00:00:00     
hashicorp                                                                                                                             | 1.4 kB  00:00:00     
(1/15): amzn2-core/2/x86_64/group_gz                                                                                                  | 2.5 kB  00:00:00     
(2/15): amzn2-core/2/x86_64/updateinfo                                                                                                | 350 kB  00:00:00     
(3/15): amzn2extra-epel/2/x86_64/primary_db                                                                                           | 1.8 kB  00:00:00     
(4/15): amzn2extra-lamp-mariadb10.2-php7.2/2/x86_64/updateinfo                                                                        |   76 B  00:00:00     
(5/15): amzn2extra-lamp-mariadb10.2-php7.2/2/x86_64/primary_db                                                                        | 464 kB  00:00:00     
(6/15): amzn2extra-python3.8/2/x86_64/updateinfo                                                                                      |   76 B  00:00:00     
(7/15): amzn2extra-docker/2/x86_64/updateinfo                                                                                         |   76 B  00:00:00     
(8/15): amzn2extra-python3.8/2/x86_64/primary_db                                                                                      |  36 kB  00:00:00     
(9/15): amzn2extra-epel/2/x86_64/updateinfo                                                                                           |   76 B  00:00:00     
(10/15): amzn2extra-docker/2/x86_64/primary_db                                                                                        |  75 kB  00:00:00     
(11/15): epel/x86_64/group_gz                                                                                                         |  95 kB  00:00:00     
(12/15): epel/x86_64/updateinfo                                                                                                       | 1.0 MB  00:00:00     
(13/15): epel/x86_64/primary_db                                                                                                       | 6.9 MB  00:00:00     
(14/15): amzn2-core/2/x86_64/primary_db                                                                                               |  50 MB  00:00:00     
(15/15): hashicorp/2/x86_64/primary                                                                                                   |  37 kB  00:00:00     
hashicorp                                                                                                                                            249/249
229 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package python38.x86_64 0:3.8.5-1.amzn2.0.2 will be installed
--> Processing Dependency: python38-libs(x86-64) = 3.8.5-1.amzn2.0.2 for package: python38-3.8.5-1.amzn2.0.2.x86_64
--> Processing Dependency: python38-setuptools for package: python38-3.8.5-1.amzn2.0.2.x86_64
--> Processing Dependency: python38-pip for package: python38-3.8.5-1.amzn2.0.2.x86_64
--> Processing Dependency: libpython3.8.so.1.0()(64bit) for package: python38-3.8.5-1.amzn2.0.2.x86_64
--> Running transaction check
---> Package python38-libs.x86_64 0:3.8.5-1.amzn2.0.2 will be installed
---> Package python38-pip.noarch 0:9.0.3-2.amzn2.0.1 will be installed
---> Package python38-setuptools.noarch 0:38.4.0-4.amzn2.0.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                 Arch                       Version                                   Repository                                Size
=============================================================================================================================================================
Installing:
 python38                                x86_64                     3.8.5-1.amzn2.0.2                         amzn2extra-python3.8                      69 k
Installing for dependencies:
 python38-libs                           x86_64                     3.8.5-1.amzn2.0.2                         amzn2extra-python3.8                     9.4 M
 python38-pip                            noarch                     9.0.3-2.amzn2.0.1                         amzn2extra-python3.8                     1.9 M
 python38-setuptools                     noarch                     38.4.0-4.amzn2.0.1                        amzn2extra-python3.8                     619 k

Transaction Summary
=============================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 12 M
Installed size: 51 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): python38-3.8.5-1.amzn2.0.2.x86_64.rpm                                                                                          |  69 kB  00:00:00     
(2/4): python38-pip-9.0.3-2.amzn2.0.1.noarch.rpm                                                                                      | 1.9 MB  00:00:00     
(3/4): python38-libs-3.8.5-1.amzn2.0.2.x86_64.rpm                                                                                     | 9.4 MB  00:00:00     
(4/4): python38-setuptools-38.4.0-4.amzn2.0.1.noarch.rpm                                                                              | 619 kB  00:00:00     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                         47 MB/s |  12 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python38-pip-9.0.3-2.amzn2.0.1.noarch                                                                                                     1/4 
  Installing : python38-setuptools-38.4.0-4.amzn2.0.1.noarch                                                                                             2/4 
  Installing : python38-3.8.5-1.amzn2.0.2.x86_64                                                                                                         3/4 
  Installing : python38-libs-3.8.5-1.amzn2.0.2.x86_64                                                                                                    4/4 
  Verifying  : python38-libs-3.8.5-1.amzn2.0.2.x86_64                                                                                                    1/4 
  Verifying  : python38-3.8.5-1.amzn2.0.2.x86_64                                                                                                         2/4 
  Verifying  : python38-pip-9.0.3-2.amzn2.0.1.noarch                                                                                                     3/4 
  Verifying  : python38-setuptools-38.4.0-4.amzn2.0.1.noarch                                                                                             4/4 

Installed:
  python38.x86_64 0:3.8.5-1.amzn2.0.2                                                                                                                        

Dependency Installed:
  python38-libs.x86_64 0:3.8.5-1.amzn2.0.2          python38-pip.noarch 0:9.0.3-2.amzn2.0.1          python38-setuptools.noarch 0:38.4.0-4.amzn2.0.1         

Complete!
  0  ansible2                        available    \
        [ =2.4.2  =2.4.6  =2.8  =stable ]
  2  httpd_modules                   available    [ =1.0  =stable ]
  3  memcached1.5                    available    \
        [ =1.5.1  =1.5.16  =1.5.17 ]
  5  postgresql9.6                   available    \
        [ =9.6.6  =9.6.8  =stable ]
  6  postgresql10                    available    [ =10  =stable ]
  8  redis4.0                        available    \
        [ =4.0.5  =4.0.10  =stable ]
  9  R3.4                            available    [ =3.4.3  =stable ]
 10  rust1                           available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0
          =stable ]
 11  vim                             available    [ =8.0  =stable ]
 15  php7.2                          available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17  =7.2.19  =7.2.21  =7.2.22  =7.2.23
          =7.2.24  =7.2.26  =stable ]
 17  lamp-mariadb10.2-php7.2=latest  enabled      \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17
          =10.2.10_7.2.19  =10.2.10_7.2.22  =10.2.10_7.2.23
          =10.2.10_7.2.24  =stable ]
 18  libreoffice                     available    \
        [ =5.0.6.2_15  =5.3.6.1  =stable ]
 19  gimp                            available    [ =2.8.22 ]
 20  docker=latest                   enabled      \
        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
 21  mate-desktop1.x                 available    \
        [ =1.19.0  =1.20.0  =stable ]
 22  GraphicsMagick1.3               available    \
        [ =1.3.29  =1.3.32  =1.3.34  =stable ]
 23  tomcat8.5                       available    \
        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50
          =stable ]
 24  epel=latest                     enabled      [ =7.11  =stable ]
 25  testing                         available    [ =1.0  =stable ]
 26  ecs                             available    [ =stable ]
 27  corretto8                       available    \
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232
          =1.8.0_242  =stable ]
 28  firecracker                     available    [ =0.11  =stable ]
 29  golang1.11                      available    \
        [ =1.11.3  =1.11.11  =1.11.13  =stable ]
 30  squid4                          available    [ =4  =stable ]
  _  php7.3                          available    \
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8  =7.3.9  =7.3.10
          =7.3.11  =7.3.13  =stable ]
 32  lustre2.10                      available    \
        [ =2.10.5  =2.10.8  =stable ]
 33  java-openjdk11                  available    [ =11  =stable ]
 34  lynis                           available    [ =stable ]
 35  kernel-ng                       available    [ =stable ]
 36  BCC                             available    [ =0.x  =stable ]
 37  mono                            available    [ =5.x  =stable ]
 38  nginx1                          available    [ =stable ]
 39  ruby2.6                         available    [ =2.6  =stable ]
 40  mock                            available    [ =stable ]
 41  postgresql11                    available    [ =11  =stable ]
  _  php7.4                          available    [ =stable ]
 43  livepatch                       available    [ =stable ]
 44  python3.8=latest                enabled      [ =stable ]
 45  haproxy2                        available    [ =stable ]
 46  collectd                        available    [ =stable ]
 47  aws-nitro-enclaves-cli          available    [ =stable ]
 48  R4                              available    [ =stable ]
 49  kernel-5.4                      available    [ =stable ]
 50  selinux-ng                      available    [ =stable ]
  _  php8.0                          available    [ =stable ]
```

無事成功しました。

```bash
Admin:~/environment/sam-app $ sam build
Building codeuri: hello_world/ runtime: python3.8 metadata: {} functions: ['HelloWorldFunction']
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
```

コンパイルもばっちりです。

# まとめ
ただのメモ書きレベルですいません！

なお、その他の言語やパッケージは、2021年3月現在は、こんな感じです。

### Python2系
```bash
Admin:~/environment/sam-app $ python2 -V
Python 2.7.18
```

### Java
```bash
Admin:~/environment/sam-app $ java --version
openjdk 11.0.10 2021-01-19 LTS
OpenJDK Runtime Environment Corretto-11.0.10.9.1 (build 11.0.10+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.10.9.1 (build 11.0.10+9-LTS, mixed mode)
```

### PHP
```bash
Admin:~/environment/sam-app $ php -v
PHP 7.2.24 (cli) (built: Oct 31 2019 18:27:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
```

### Ruby
```bash
Admin:~/environment/sam-app $ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
```

### Node.js
```bash
Admin:~/environment/sam-app $ node -v
v10.24.0
```

### Go
```bash
Admin:~ $ go version
go version go1.15.8 linux/amd64
```

# 補足
2021年3月現在、LambdaではPython3.9はサポートされてませんが、そもそもPython3.9自体、yumでのインストールに対応していないので、どうしてもCloud9（Amazon Linux2）にインストールしたい場合は、自身でコンパイルするしか方法がなさそうです。