[PYTHON] [AWS CLI] Enable the AWS CLI on Red Hat Enterprise Linux 8

Target

· Install the AWS CLI on a Red Hat Enterprise Linux 8-based EC2 instance. -Enable resource operations in the target AWS account using the AWS CLI.

Trigger

It is almost a memorandum. When I tried to use the AWS CLI (*) on Red Hat Enterprise Linux 8 I wrote it because I was a little annoyed by command not found in python related commands.

※AWS CLI A type of API provided by AWS that enables AWS resource operations on the command line.

Usage environment

Hardware: ** AWS EC2 server ** OS(AMI) : Red Hat Enterprise Linux 8 (HVM), SSD Volume Type Other software: Python 3.8.0 aws-cli/1.18.81 Python/3.8.0 Linux/4.18.0-193.el8.x86_64 botocore/1.17.4

Workflow

Item number title
1 python installation
2 AWS CLI installation
3 Issuance of access key ID and secret access key
4 AWS CLI operation check

procedure

1. Install python

Since the AWS CLI is based on python, you need to have the python execution environment installed first. But Red Hat Enterprise Linux 8 doesn't seem to have python installed by default, First, install it (*). As of June 17, 2020, I installed the latest python3.8 with yum.

** ① Install python3.8 ** Run yum install python38 ⇒ It should be output as Complete!.

[root@ip-172-31-45-222 ~]# yum install python38
Installed:
  python38-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64                       python38-libs-3.8.0-6.module+el8.2.0+5978+503155c0.x86_64
  python38-pip-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch                  python38-pip-wheel-19.2.3-5.module+el8.2.0+5979+f9f0b1d2.noarch
  python38-setuptools-41.6.0-4.module+el8.2.0+5978+503155c0.noarch           python38-setuptools-wheel-41.6.0-4.module+el8.2.0+5978+503155c0.noarch

Complete!

** ② python command operation check ** Execute python3 --version (Note that in RHEL the version must also be included in the command) ⇒ Version information should be output normally


[root@ip-172-31-45-222 ~]# python3 --version
Python 3.8.0

2. Install AWS CLI

** ① AWS CLI installation ** Run pip3 install awscli ⇒ It should be output as Successfully installed.

[root@ip-172-31-45-222 ~]# pip3 install awscli
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting awscli
  Downloading https://files.pythonhosted.org/packages/9f/13/a93f9ef5d6a0820dbd324a222aba7ff299454cbc0f8c8d37d918e3b530fb/awscli-1.18.81.tar.gz (1.2MB)
     |????????????????????????????????| 1.2MB 7.3MB/s
Collecting botocore==1.17.4 (from awscli)
  Downloading https://files.pythonhosted.org/packages/bc/83/e5c0420ed9d628c6cd054c8a0782dece06515a90b63de4e1c3ce2b943dc2/botocore-1.17.4-py2.py3-none-any.whl (6.3MB)
     |????????????????????????????????| 6.3MB 23.7MB/s
Collecting docutils<0.16,>=0.10 (from awscli)
  Downloading https://files.pythonhosted.org/packages/22/cd/a6aa959dca619918ccb55023b4cb151949c64d4d5d55b3f4ffd7eee0c6e8/docutils-0.15.2-py3-none-any.whl (547kB)
     |????????????????????????????????| 552kB 36.8MB/s
Collecting rsa<=3.5.0,>=3.1.2 (from awscli)
  Downloading https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl (46kB)
     |????????????????????????????????| 51kB 27.9MB/s
Collecting s3transfer<0.4.0,>=0.3.0 (from awscli)
  Downloading https://files.pythonhosted.org/packages/69/79/e6afb3d8b0b4e96cefbdc690f741d7dd24547ff1f94240c997a26fa908d3/s3transfer-0.3.3-py2.py3-none-any.whl (69kB)
     |????????????????????????????????| 71kB 32.6MB/s
Collecting PyYAML<5.4,>=3.10 (from awscli)
  Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (269kB)
     |????????????????????????????????| 276kB 37.7MB/s
Collecting colorama<0.4.4,>=0.2.5 (from awscli)
  Downloading https://files.pythonhosted.org/packages/c9/dc/45cdef1b4d119eb96316b3117e6d5708a08029992b2fee2c143c7a0a5cc5/colorama-0.4.3-py2.py3-none-any.whl
Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.17.4->awscli)
  Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
     |????????????????????????????????| 235kB 41.5MB/s
Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.17.4->awscli)
  Downloading https://files.pythonhosted.org/packages/07/cb/5f001272b6faeb23c1c9e0acc04d48eaaf5c862c17709d20e3469c6e0139/jmespath-0.10.0-py2.py3-none-any.whl
Collecting urllib3<1.26,>=1.20; python_version != "3.4" (from botocore==1.17.4->awscli)
  Downloading https://files.pythonhosted.org/packages/e1/e5/df302e8017440f111c11cc41a6b432838672f5a70aa29227bf58149dc72f/urllib3-1.25.9-py2.py3-none-any.whl (126kB)
     |????????????????????????????????| 133kB 47.5MB/s
Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)
  Downloading https://files.pythonhosted.org/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
     |????????????????????????????????| 81kB 35.4MB/s
Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.17.4->awscli)
  Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, docutils, jmespath, urllib3, botocore, pyasn1, rsa, s3transfer, PyYAML, colorama, awscli
  Running setup.py install for PyYAML ... done
  Running setup.py install for awscli ... done
Successfully installed PyYAML-5.3.1 awscli-1.18.81 botocore-1.17.4 colorama-0.4.3 docutils-0.15.2 jmespath-0.10.0 pyasn1-0.4.8 python-dateutil-2.8.1 rsa-3.4.2 s3transfer-0.3.3 six-1.15.0 urllib3-1.25.9

** ② AWS CLI installation confirmation ** ʻAws --version` run ⇒ Version information should be output normally


[root@ip-172-31-45-222 ~]# aws --version
aws-cli/1.18.81 Python/3.8.0 Linux/4.18.0-193.el8.x86_64 botocore/1.17.4

3. Issuance of access key ID and secret access key

To access resources in your AWS account from the AWS CLI You'll need your access key ID and secret access key, so publish them on the AWS console.

** ① Access to the following ** https://console.aws.amazon.com/iam/home?#/security_credential

** ② Click Create new access key ** tempsnip.png

** ③ Click Download key file ** After clicking, a file called "rootkey.csv" will be downloaded. The access key ID and secret access key are listed in it. tempsnip.png

3. Load the access key ID and secret access key into the AWS CLI

ʻAws configure` run Enter values (*) in each item as shown below.


[root@ip-172-31-45-222 ~]# aws --version
aws-cli/1.18.81 Python/3.8.0 Linux/4.18.0-193.el8.x86_64 botocore/1.17.4
[root@ip-172-31-45-222 ~]# aws configure
AWS Access Key ID [None]: {rootkey.AWSAccessKeyId described in csv}
AWS Secret Access Key [None]: {rootkey.AWS Secret Key described in csv}
Default region name [None]: ap-northeast-1
Default output format [None]: json

4. AWS CLI operation check

Install jq to cut out the output value of json.

Run sudo yum install jq ⇒ It should be displayed as Complete!


[root@ip-172-31-45-222 ~]# sudo yum install jq

Installed:
  jq-1.5-12.el8.x86_64                                                      oniguruma-6.8.2-1.el8.x86_64

Complete!

aws ec2 describe-instances | jq '.Reservations[].Instances[] | {InstanceId, PrivateIpAddress}' (Cut out and display the instance ID and private IP of all instances) ⇒The ID and IP address of each instance should be displayed normally.


[root@ip-172-31-45-222 ~]# aws ec2 describe-instances | jq '.Reservations[].Instances[] | {InstanceId, PrivateIpAddress}'
{
  "InstanceId": "i-0e2d37561986006ae",
  "PrivateIpAddress": "172.31.42.251"
}
{
  "InstanceId": "i-04b2b0295c4ace2c8",
  "PrivateIpAddress": "172.31.42.211"
}
{
  "InstanceId": "i-05479d1f45744d4e6",
  "PrivateIpAddress": "172.31.33.200"
}
{
  "InstanceId": "i-01996d692bf2eeee6",
  "PrivateIpAddress": "172.31.34.245"
}
{
  "InstanceId": "i-07e3cd75ed7d0e213",
  "PrivateIpAddress": "172.31.34.137"
}
{
  "InstanceId": "i-01ea4405ab69ba0fd",
  "PrivateIpAddress": "172.31.45.222"
}

Recommended Posts

[AWS CLI] Enable the AWS CLI on Red Hat Enterprise Linux 8
Red Hat Enterprise Linux 8.3 Various confirmations
Enable zfs on the Springdale Linux 8.3 installation ISO image
Install the JDK on Linux
Paste the link on linux
How to install nkf with rpm file on Red Hat Enterprise Linux 7.7 (for non-internet environment)
Notes on using OpenCL on Linux on the RX6800
Including docker-nginx port forwarding on AWS Linux 2
Compiling the Linux kernel (Linux 5.x on Ubuntu 20.04)
The day when the flask server running on linux on AWS was semi-persistent (running in the background)
[Linux] Review of commands for deploying on AWS
Get the latest AMI information with the AWS CLI
[2020July] Check the UDID of the iPad on Linux
[AWS S3] Confirmation of the existence of folders on S3
Set the startup script on Linux (RasPi, Edison)