5

Installing and configuring AWS CLI

 3 years ago
source link: https://help.dreamhost.com/hc/en-us/articles/216335908-Installing-and-configuring-AWS-CLI
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Installing and configuring AWS CLI

Overview

AWS CLI is a command-line tool for managing data in Amazon S3 and other Cloud Storage Service Providers that use the S3 protocol such as DreamObjects. It's best suited for users who are competent with the command-line and is ideal for scripts that are automated and triggered from a cronjob.

The following instructions help you install and configure AWS CLI to work with DreamObjects.

Do I need to manually install AWS?

AWS-CLI is installed on all servers. However, if you require a newer version, you would need to install this manually in a Python virtual environment.

If so, proceed with the steps below. Otherwise, skip to configuring AWS below.

Installing a custom version of AWS CLI

Mac and Linux computers

Mac and Linux machines can install aw-cliby running the Python “pip” command. The following shows how to install aws-cli on a DreamHost server, however the steps are the same for Mac and Linux machines.

DreamHost servers

The following steps install a custom version of Python 3, create a virtualenv, and install aws-cli within that virtualenv.

  1. Log into your server via SSH.
  2. Install a custom version of Python of your choice.

    dh-kb-important-icon.svg

    Due to a kernel update with Ubuntu, you must install Python 2.7.15 or newer in order to create a virtualenv.

  3. Make sure you're in your user's home directory.
    [server]$ cd ~
  4. Run the following command to create a virtual environment for a specific DreamObjects bucket.
    • This virtual environment will store your DreamObjects bucket's credentials.
    • This example names the virtual environment after your DreamObjects bucket name.
    • The following command also assumes you've installed a custom version of Python as mentioned above. You can then specify the full path to your local install when creating the virtual environment.
    • Make sure to change username to your Shell user and my-bucket to your DreamObjects bucket.
    [server]$ virtualenv -p /home/username/opt/python-3.9.2/bin/python my-bucket
  5. Activate this new virtual environment.
    [server]$ source ~/my-bucket/bin/activate
  6. When you activate the virtual environment, the command prompt changes to show it's active. For example:
    (my-bucket) 
  7. Install aws-cli.
    (my-bucket) pip install awscli
  8. Finally, update the permissions on the new aws directory so you can run aws commands.
    (my-bucket) chmod +x ~/my-bucket/bin/aws

You can now proceed with configuring it to use your DreamObjects bucket.

Configuring your user to automatically use the new virtual environment

When you activate the virtual environment as shown above, it is only activated during your current session. If you log out and log back in, it will no longer be active.

To automatically activate your virtual environment when you log in, add the following line to your .bash_profile.

source ~/my-bucket/bin/activate

Just change my-bucket to the name of the virtual environment you created.

Configuring AWS CLI

Run the following command to input your Access and Secret key for your bucket. aws-cli stores them encrypted for you.

Set the Default region to us-east-1.

Do not enter anything for the Default output format, then press Enter.

[user@localhost]$ aws configure
AWS Access Key ID: **********
AWS Secret Access Key: **********
Default region name: us-east-1
Default output format [None]:

You can now run aws-cli commands to interact with your DreamObjects bucket.

Example Commands

View the following articles for examples of commands you can use to manage your DreamObjects data:

Start Storing Your Data Today!

Did this article answer your questions?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK