Practical articles on AWS architecture, migration, security, and AI tooling — written from the trenches of migrating Go3 OTT to AWS.

In the first part of this article Using Visual Studio Code for CLI and Python tasks on AWS - part 1 I have covered the installation of Python3 and Visual Studio Code. Now we will focus on the installation of AWS CLI. Thanks to this, we will be able to connect to AWS resources from our local machine.
The AWS CLI (Command Line Interface) is a powerful tool for managing your AWS resources and services through a command-line interface. It allows you to interact with AWS resources using commands in your terminal (or Command Prompt on Windows) rather than using the AWS Management Console or SDK.
The AWS CLI can be useful in a variety of scenarios, including:
Automating repetitive tasks: If you have to perform the same AWS-related tasks regularly, you can use the AWS CLI to automate these tasks by writing scripts that perform the required actions.
Developing and testing applications: Developers can use the AWS CLI to test and deploy their applications using scripts or automation tools. This can help streamline the development and deployment process.
Managing AWS resources in a serverless environment: The AWS CLI is especially useful for managing AWS resources in a serverless environment, where you might be creating and deploying Lambda functions, API Gateway, S3 buckets, and other serverless components using the AWS CLI.
Managing AWS resources across multiple accounts and regions: With the AWS CLI, you can manage AWS resources across multiple accounts and regions using a single tool, making it easy to automate and manage complex AWS environments.
Integrating with other tools and services: The AWS CLI can be integrated with other tools and services, such as Jenkins, Git, and Docker, to automate the deployment and management of AWS resources in these environments.
If you have sudo permissions, you can install the AWS CLI for all users on the computer:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
In case you are not able to do this, you can follow the instructions from AWS: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html.
Just run:
sudo apt install awscli
Download the MSI installer from the official website: https://aws.amazon.com/cli/ and run the installer. Make sure to select Add Python to environment variables during the installation process.
Before we can use AWS CLI we need to set up the necessary configuration settings to communicate with the AWS services. There are two methods of achieving this. First is to use the access key ID and secret access key, however this is not recommended anymore. Instead, we can enable authentication through a user in IAM Identity Center.
To configure AWS CLI to authenticate through a user in IAM Identity Center, you need to have to enable access through the IAM Identity Center. You can follow my article Easier access to multiple accounts with IAM Identity Center.
Once you established access through IAM Identity Center, you can follow these steps:
Unlike the administrative permission set, which uses AdministratorAccess permissions, the PowerUserAccess permission set doesn’t allow management of users and groups.
Once we have the user with PowerUserAccess permissions created, you can configure the AWS CLI using the following commands:
$ aws configure sso
SSO session name (Recommended): my-sso
SSO start URL [None]: https://my-sso-portal.awsapps.com/start
SSO region [None]: eu-north-1
SSO registration scopes [None]: sso:account:access
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
https://device.sso.eu-north-1.amazonaws.com/
Then enter the code:
You will see your browser opening and you will need to log in to your PowerUserAccess account. Then you will need to allow CLI (called botocore-client) to access AWS IAM Identity Center accounts and permission sets.

After this, you will be presented with the account, to which you want to log in to your AWS CLI. You need to select one.
SQTM-CXXB
There are 6 AWS accounts available to you.
> Bootcamp (123456789011)
Bootcamp-PROD (123456789012)
Backups (123456789013)
BootcampSandbox (123456789014)
Wojciech Doganowski (123456789015)
Liczyrzepa-PROD (123456789016)
After selecting the account, you will be prompted to which region you want the CLI to be logged in:
Using the account ID 123456789011
The only role available to you is: PowerUserAccess
Using the role name "PowerUserAccess"
CLI default client Region [None]: eu-north-1
CLI default output format [None]: YAML
CLI profile name [PowerUserAccess-123456789011]:
To use this profile, specify the profile name using --profile, as shown:
aws s3 ls --profile PowerUserAccess-123456789011
$
That’s it! You have now configured AWS CLI to authenticate through a user in IAM Identity Center using access keys. Let’s try to access S3:
$ aws s3 ls --profile PowerUserAccess-123456789011
2023-04-01 19:24:29 python-session-1-dogan
This results in creating the sso-session section and named profile in ~/.aws/config that looks like the following:
[profile PowerUserAccess-123456789011]
sso_session = my-sso
sso_account_id = 123456789011
sso_role_name = PowerUserAccess
region = eu-north-1
[sso-session my-sso]
sso_start_url = https://my-sso-portal.awsapps.com/start
sso_region = eu-north-1
sso_registration_scopes = sso:account:access
To be able to use the AWS CLI next time, you will need to login to SSO using the following command:
aws sso login --profile PowerUserAccess-123456789011
You will be asked to login into the browser window again, the same way as while creating the SSO account.
To avoid adding –profile PowerUserAccess-123456789011 to each AWS CLI command, you can set the AWS_PROFILE variable in the following way:
On Linux or Mac:
export AWS_PROFILE=PowerUserAccess-123456789011
On Windows:
SET AWS_PROFILE=PowerUserAccess-123456789011
Then you can run AWS CLI commands like this:
$ aws s3 ls
2023-04-01 19:24:29 python-session-1-dogan
To logout the AWS CLI session, you need to use:
aws sso logout
You have configured the AWS CLI to use the IAM Identity Center as the SSO.
It’s important to note that the access key ID and secret access key are sensitive information that should be kept secure. For that reason, we should avoid using them as if someone will get the access to this key pair, would have the same access to your account as you.
Following are the steps to get the access key ID and secret access key:
Note that you should treat your access key ID and secret access key as sensitive information and keep them secure. Do not share them with others, and rotate them regularly to ensure the security of your AWS account.
Configure the AWS CLI: Run the following command in the terminal or command prompt window: aws configure. This will launch a wizard that will guide you through the process of configuring the AWS CLI:
$ aws configure
AWS Access Key ID [None]: ********************
AWS Secret Access Key [None]: ********************
Default region name [None]: us-east-1
Default output format [None]: YAML
Test the AWS CLI: Once the AWS CLI is configured, you can test it by running a command such as aws s3 ls. This will list the contents of your default S3 bucket (assuming you have one).
$ aws s3 ls
2023-04-01 19:21:39 python-session-1-dogan
Great, we have the development IDE and the AWS CLI installed.
Up to now, we have the Python and Visual Studio Code installed together with AWS CLI. In the next part of this article - Using Visual Studio Code for CLI and Python tasks on AWS - part 3 - we will install the Boto3 library.