What is Boto?
Boto is an Amazon AWS
SDK for python. Ansible internally uses Boto to connect to Amazon EC2 instances and hence you need Boto library in order to run Ansible on your laptop/desktop.
Recently I started playing with Amazon EC2
and wanted to start
, stop
Amazon EC2 instances using command line.
One of the requirement for you to install Amazon CLI
(Command Line Interface) is to install Boto on your system. I’m using Macbook Pro 13″ for all of my development.
In this tutorial we will go over steps on how to install Boto and Boto3
on MacOS.
- Follow tutorial how to setup, configure and run Amazon CLI command on macOS?
Here are commands:
Step-1:
Install BOTO3.
Command:
pip install boto3 --user
bash1.2 $ pip install boto3 --user DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Collecting boto3 Downloading https://files.pythonhosted.org/packages/34/53/e7953f300d345f8b95a578085aba17bc7145f913b32e1f00f9a105602851/boto3-1.9.143-py2.py3-none-any.whl (128kB) 100% || 133kB 808kB/s Collecting s3transfer<0.3.0,>=0.2.0 (from boto3) Using cached https://files.pythonhosted.org/packages/d7/de/5737f602e22073ecbded7a0c590707085e154e32b68d86545dcc31004c02/s3transfer-0.2.0-py2.py3-none-any.whl Collecting jmespath<1.0.0,>=0.7.1 (from boto3) Using cached https://files.pythonhosted.org/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl Collecting botocore<1.13.0,>=1.12.143 (from boto3) Downloading https://files.pythonhosted.org/packages/e0/9a/400c9a3634f7f40453634609925131f9b0c11903b06d0cc7270be3f0c372/botocore-1.12.143-py2.py3-none-any.whl (5.4MB) 100% || 5.4MB 3.4MB/s Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer<0.3.0,>=0.2.0->boto3) Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl Collecting urllib3<1.25,>=1.20; python_version == "2.7" (from botocore<1.13.0,>=1.12.143->boto3) Using cached https://files.pythonhosted.org/packages/01/11/525b02e4acc0c747de8b6ccdab376331597c569c42ea66ab0a1dbd36eca2/urllib3-1.24.3-py2.py3-none-any.whl Collecting python-dateutil<3.0.0,>=2.1; python_version >= "2.7" (from botocore<1.13.0,>=1.12.143->boto3) Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl Collecting docutils>=0.10 (from botocore<1.13.0,>=1.12.143->boto3) Downloading https://files.pythonhosted.org/packages/50/09/c53398e0005b11f7ffb27b7aa720c617aba53be4fb4f4f3f06b9b5c60f28/docutils-0.14-py2-none-any.whl (543kB) 100% || 552kB 1.1MB/s Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore<1.13.0,>=1.12.143->boto3) Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl matplotlib 1.3.1 requires nose, which is not installed. matplotlib 1.3.1 requires tornado, which is not installed. Installing collected packages: futures, urllib3, jmespath, six, python-dateutil, docutils, botocore, s3transfer, boto3 Successfully installed boto3-1.9.143 botocore-1.12.143 docutils-0.14 futures-3.2.0 jmespath-0.9.4 python-dateutil-2.8.0 s3transfer-0.2.0 six-1.12.0 urllib3-1.24.3
As you see in above log it’s complaining about missing nose
and tornado
dependencies.
Just execute below command to install both dependencies.
bash1.2 $ pip install nose --user bash1.2 $ pip install tornado --user
Step-2:
Install BOTO too:
pip install boto --user
That’s it.
Step-3: Setup Amazon AWS Credentials (2 approaches)
1. Setup Boto config file:
- Open boto
config
file- $ vi /etc/boto.cfg
- Add below line to the file.
[Credentials] aws_access_key_id = QAYXNIWNWKSWIY27AIF aws_secret_access_key = W8S8RyJwSCRKOAKIAYXNIWNWKSWIY27AIFokKTqcaNV
OR
2. Setup aws credentials file:
- Open
credentials
file using command- vi ~/.aws/credentials
- Add below line to the file.
bash-3.2$ cat ~/.aws/credentials [default] aws_access_key_id=QAYXNIWNWKSWIY27AIF aws_secret_access_key=W8S8RyJwSCRKOAKIAYXNIWNWKSWIY27AIFokKTqcaNV
How to set default Amazon EC2 region?
- Open config file using command
- vi ~/.aws/config
- Add below lines to the file.
[default] region=us-east-2
That’s it. Now you have successfully setup Boto3 and you are now good to run Ansible command and Amazon CLI.