Search the Community
Showing results for tags 'aws cli'.
-
AWS offers numerous services for anyone to use. However, when you want an easy and controlled way of controlling all your AWS services, you must install an AWS CLI (command-line interface). The AWS CLI gives you access to the AWS API, allowing you to manage all the services depending on the task you are handling or want to automate. You can install the AWS CLI on Ubuntu 24.04, and there are two approaches you can use depending on your preference. You can install it as a snap package or a Python module inside a Python virtual environment. Let’s discuss each option. Method 1: Install AWS CLI Via Snap Ubuntu supports AWS CLI, and you can access it as a snap package from App Center via GUI or using the snap command. Installing AWS CLI as a snap will install all the dependency packages it requires without installing them separately. If you find this approach convenient, execute the below command to install AWS CLI. $ sudo snap install aws-cli --classic AWS CLI will be downloaded and installed on your system. With this option, the AWS CLI is accessible system-wide and not just in a virtual environment, as in the second method. Once you install AWS CLI, check the installed version to ascertain the package has been installed successfully. $ aws --version We’ve installed AWS CLI version 2.15.38. The next step is to set up the AWS CLI by connecting it with your AWS account to allow you to take control of your AWS services. Run the configure command below. $ aws configure Provide your credentials to complete the setup. Method 2: Install AWS CLI as a Python Module You can also install AWS CLI on Ubuntu 24.04 as a Python module. This method requires creating a virtual environment and using pip to install AWS CLI. A virtual environment is a secluded way of using packages. Instead of making AWS CLI accessible system-wide, you can limit it to only being accessible inside the created virtual environment. Besides, if you don’t have sudo privileges on the system, provided you have a virtual environment, you will manage to install AWS CLI. Follow the steps below. Step 1: Install Python3 PIP and Venv To create a virtual environment, we must have Venv installed. Execute the below command to install it. $ sudo apt install Python3-venv You also need PIP to help with installing Python modules. Therefore, install PIP using the following command. $ sudo apt install python3-pip Step 2: Create a Virtual Environment With Venv, we can create a secluded environment in which to install AWS CLI without requiring sudo privileges. A virtual environment is recommended when working with Python modules, as it doesn’t interfere with APT-installed packages. Besides, if things go sideways, it doesn’t affect your system. We are using Python 3 for this case. Here’s how you create a virtual environment and activate it. $ python3 -m venv .venv $ source .venv/bin/activate We’ve named the virtual environment “venv,” but you can use any preferred name. Again, we’ve created the directory in our current location, but you can specify a different path. Step 3: Install AWS CLI Inside the virtual environment, running the following command will download and install AWS CLI. $ pip3 install awscli Ensure the download completes successfully. You will get an output similar to the one below. You can check the installed version. $ aws --version With AWS CLI installed, configure it to start managing your AWS services. Once you are done using it or want to exit the virtual environment, deactivate it. Conclusion AWS CLI is a preferred way of managing your AWS services. On Ubuntu 24.04, you can install it as a snap package or in a Python virtual environment using PIP. This post discussed each method, giving examples to create a detailed and straightforward guide for anyone to follow along. View the full article
-
aws cli What are the Environment Variables to Configure the AWS CLI?
Linux Hint posted a topic in Linux
Amazon has a load of cloud services for various solutions and uses. It offers a ton of cloud services and applications to help users architect their own solutions. It has an interactive interface to access the services and tools on the platform. AWS services and applications can also be accessed and used through the AWS Command Line Interface (CLI). This article will be a brief introduction to the AWS CLI and the environment variables required to configure the AWS CLI. What is AWS CLI? It is an open-source command line tool to access your AWS account and use the services and applications just like the console. With the help of a few commands, users can create their solutions with any graphical interface such as in AWS Console. It is quite easy and simple to install AWS CLI. Before using AWS CLI, there are a few environment variables that are configured. This article will explain the environment variables and how to configure them. What are the Environment Variables to Configure the AWS CLI? To use AWS services, variables are required according to their given environment called environment variables. These variables are configured before using the AWS services through CLI. Some of these variables are given below: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_SESSION_TOKEN AWS_DEFAULT_OUTPUT Let us discuss these configuration variables for CLI in detail and how they are used: AWS_ACCESS_KEY_ID This variable holds the access key id which is a unique identifier of your requests with your AWS account. Open CMD and set this variable using the command given below: set AWS_ACCESS_KEY_ID=<Your Access Key ID> The access key id is set now. There will be no responsive output to the command as shown in the figure below: Let us head to the next environment variable: AWS_SECRET_ACCESS_KEY This variable holds the corresponding pass key to the above-mentioned “Key_ID”. The following command configures this pass key: set AWS_SECRET_ACCESS_KEY=<Your secret key> This command also has no visible output on the screen but this environment variable is set. Refer to the image below: Let us head to the next environment variable: AWS_DEFAULT_REGION This environment variable defines the region of your AWS account. Use the code below to set the desired region: set AWS_DEFAULT_REGION==<Your region> See the below image for a better understanding: Let us move on to the next environment variable: AWS_SESSION_TOKEN This variable comes into play when security credentials are required on a temporary basis. Security Token Service (STS) serves the purpose of allowing temporary access with the help of session tokens. Use the below command to set the session token: set AWS_SESSION_TOKEN=<Your Session Token> See the below image for a better understanding: Let us head to the next variable in line: AWS_DEFAULT_OUTPUT This configuration variable sets the output data type. The default output data type is JSON. Let us change this to text. See the code below: set AWS_DEFAULT_OUTPUT=text Again, there is no visible output of the command but the output data type has been changed to text. See the below image for a better understanding: There is another way where all the above environment variables can be configured with one command except for “AWS_SESSION_TOKEN”. Use the command below: aws configure The below output can be seen on the screen: Provide the details according to the fields. Miscellaneous There are a ton of other environment variables that can be set when using different services of AWS. The variables that are discussed above are the core and fundamental variables. Click here to view all the variables that can be configured using AWS CLI. The commands we used in the above scenarios are supported by the “WINDOWS” terminal, i.e., “CMD”. Let us see the Linux commands to configure AWS CLI environment variables. Linux The process of configuring AWS CLI environment variables is the same. The commands are the same as Windows. For “Linux” simply replace “set” with “export” in the commands that are given above. This article has concisely explained the environment variable to configure the AWS CLI. Conclusion AWS CLI provides a powerful solution to use AWS cloud services without the console. There are a number of environment variables, such as “AWS_ACCESS_KEY_ID”, “AWS_SECRET_ACCESS_KEY”, “AWS_DEFAULT_REGION”, “AWS_SESSION_TOKEN”, and “AWS_DEFAULT_OUTPUT” that can be set with the help of AWS CLI. This article is a tutorial for configuring AWS CLI environment variables. View the full article -
AWS CLI or Amazon Web Service Command Line Interface is a command-line tool for managing and administering your Amazon Web Services. AWS CLI provides direct access to the public API (Application Programming Interface) of Amazon Web Services. Since it’s a command-line tool, you can also use it to create scripts for automating your Amazon Web Services. In this article, I will show you how to install the AWS CLI program on Ubuntu 22.04 LTS using the APT package manager. I will also show you how to install the latest version of the AWS CLI program on Ubuntu 22.04 LTS as a Python module using Python PIP. So, let’s get started… View the full article
-
You can configure the AWS CLI to assume an IAM role for you in combination with MFA. If you are a power user of the CLI, you will realize that you have to enter your MFA token every 60 minutes, which is annoying. /images/2019/08/timeout.jpg You will learn how to fix that in the following. AWS account setup Let’s assume we have three AWS accounts. Account id Alias Description 000000000000 iam Only IAM users are created in this account 111111111111 dev Development workloads 222222222222 prod Production workloads Besides that: In the iam account, an IAM user named michael is created. MFA is enabled, and an access key is generated. In the dev and prod accounts, the following IAM role is created (CloudFormation template): --- AWSTemplateFormatVersion: '2010-09-09' Resources: AdminRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: AWS: 'arn:aws:iam::000000000000:root' # replace this with your iam account id Action: 'sts:AssumeRole' Condition: Bool: 'aws:MultiFactorAuthPresent': true ManagedPolicyArns: - 'arn:aws:iam::aws:policy/AdministratorAccess' MaxSessionDuration: 43200 # 12 hours in seconds RoleName: Admin Ensure that you set the MaxSessionDuration property! The default is 60 minutes. Configuring the AWS CLI The AWS CLI stores the configuration in ~/.aws/credentials (or %UserProfile%\.aws\credentials if you are using Windows). First of all, configure the access key from the michael IAM user using the aws_access_key_id and aws_secret_access_key configuration values. The value between the square brackets is called the profile name. [iam] aws_access_key_id = AKIA**************** aws_secret_access_key = **************************************** After that, configure the IAM roles you want to assume. The following configuration values are used: Configuration value Description role_arn ARN of the role you want to assume source_profile Reference the profile of the IAM user mfa_serial ARN of the virtual MFA device or the serial number for a hardware device duration_seconds The expiry of the credentials returned by the assume role call Ensure that you set the duration_seconds property! The default is 60 minutes. Add the following profiles to the credentials file. [dev] role_arn = arn:aws:iam::111111111111:role/Admin source_profile = iam mfa_serial = arn:aws:iam::000000000000:mfa/michael duration_seconds = 43200 [prod] role_arn = arn:aws:iam::222222222222:role/Admin source_profile = iam mfa_serial = arn:aws:iam::000000000000:mfa/michael duration_seconds = 43200 Using the profiles The --profile parameter lets you specify the profile you want to use when working with the CLI. aws --profile dev s3 ls aws --profile prod s3 ls The AWS CLI will ask you for your MFA token the first time you make a call. You can also set the AWS_PROFILE environment variable to avoid typing --profile ... all the time. export AWS_PROFILE=dev aws s3 ls Summary To avoid frequent re-enter of the MFA token when using the AWS CLI, you have to adjust the MaxSessionDuration of the IAM role and the duration_seconds configuration value of the AWS CLI. View the full article
-
Forum Statistics
63.6k
Total Topics61.7k
Total Posts