AWS Access Simplified: A Step-by-Step Guide to Console, CLI, and SDK
Learn the Ins and Outs of AWS Access with Console, CLI, and SDK.
Introduction
Amazon web services(AWS) are the most used cloud provider in the market. Amazon web service's market share is about 32% of the total cloud service market. It has a wide range of cloud services that you can use for your apps. Before learning how to use the AWS services first, you need to know how you can access AWS.
There are more than one ways to access AWS and its services. This blog tutorial will show you different ways to access AWS with step-by-step instructions.
Prerequisite
Before we start learning,
First, you should have an account on AWS.
Basic knowledge of any programming language.
Basic knowledge of CLI Commands.
Basic knowledge of AWS services like IAM.
How to Access AWS?
There are many ways you can access AWS. In this blog tutorial, we will use the most common way to access AWS. You can access AWS in any way depending on your needs, preferences, and use case.
AWS Management Console
AWS Command Line Interface (CLI)
AWS Software Development Kit (SDK)
AWS Management Console
AWS management console is a web-based GUI that helps you to operate AWS services. It's an easy way to interact with AWS resources, You can deploy, manage, and monitor your app all in one place.
Here are the steps to access the AWS management console
Go to https://aws.amazon.com/ and click on the “Sign in” button.
Login with your registered email and password. If you don't have an AWS account then create your account by clicking on the “Create a new AWS Account” button. (Im using my root account for this tutorial)
Once you are successfully logged in to your AWS Account. It will navigate you to the management console. Now you can navigate to different services by searching or by clicking on the top left Icon services.
So Takeaway from this method is, the AWS Management Console is the easiest way to get work done quickly and you can access all the AWS services using GUI. You do not need to write any code or command, it's simple to use because of the rich GUI and more user-friendly.
Before we learn how to access AWS using CLI & SDK. First, you need to know about the “Access Key” & “Secret Key”.
What is Access Key & Secret Key and why it is important?
For using AWS CLI and AWS SDK, You need an "Access Key" and "Secret Key". The access key is like a username and the Secret key is like a Password for your account. Without the keys, you can't access AWS services/accounts using CLI and AWS SDK. To generate the Access key, I am using an IAM user Account, Access key should be IAM user-specific and every IAM user can generate their own Access Keys. Don't use your root account for generating Access and Secret key.
IAM stands for Identity and Access Management.
NOTE: Keep your access key private from everyone. Please don’t share it with anyone.
Follow these steps to generate access and secret keys:
Go to your AWS Management Console. Search for IAM Services
You will see the users tab on the left-hand side, Click on the user tab and it will navigate to the user's page where it shows the list of IAM users
Click on users here it shows “pradhu_admin”. You will be able to see your user's details. Now click on the security credentials tab.
Scroll down and you will find a button named "Create Access Key" Click on it.
Choose Command Line Interface (CLI) and click on the Next Button.
Add a Description for your access key and then click on Create Access Key button.
Your Access Key and Secret Key are generated. Now you can copy it to your code or download the file and store somewhere safe where no one access those files/codes.
Now you can use the Access key and Secret key to access AWS CLI or AWS SDK.
NOTE:- The secret access key can only be viewed or downloaded at this time only. It cannot be recovered later. However, you can create a new access key at any time.
AWS Command Line Interface (CLI)
Using AWS CLI, You can access AWS services right from your operating system using CLI Tool. Using AWS CLI you can automate your task like starting or stopping services, starting-restart- terminate your EC2 instances, deploying or configuring your code, and many more.
AWS CLI supports multiple operating systems including Windows, Mac, and Linux. This allows you to use the same AWS CLI command and scripts across different operating systems.
To use AWS CLI, you have to first download AWS CLI Tool. You can download using the link below 👇
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
Follow the instructions given in the link and download the AWS CLI using CMD or GUI for your supported operating system.
I’m assuming you have installed the AWS CLI Tool in your system and everything is working so far.
Run Command aws –-version
to check if it's installed properly
If you get a result like the above image, that means your AWS CLI is installed properly
Now let's look at how you can access AWS using AWS CLI Tool.
Open up your terminal/AWS CLI. I'm using Iterm2 as a terminal.
First, you need to configure your AWS CLI. To configure you need to run cmd
aws configure
It will ask you to enter your AWS Access key. Enter or Paste your Access Key then press "Enter".
It will ask you to enter your AWS Secret key. Enter or Paste your Secret Key then press "Enter".
Now, it will ask you to enter your Default Region Name. Enter the region name which is close to you. I'm going to enter ap-south-1 (Asia Pacific-Mumbai) and then press "Enter".
To get region name. Click on the Global link above on the IAM service Page. It will show all the region names.
Now, it will ask you to enter your Default output format. Just press enter, we are not going to enter any output format in this tutorial.
To check if your AWS CLI is connected to AWS. Use CMD
aws iam list-users
using the cmd it will show a list of IAM users.Now Your AWS CLI is configured. Congratulations 🎉
If anything goes wrong or shows any error. Follow all the above steps again and it should work or you can search for your error/issue on google and figure out the solution.
To know about more AWS CLI commands. Use this link below 👇
https://docs.aws.amazon.com/cli/latest/index.html
AWS Software Development Kit (SDK)
Using AWS (Software Development Kit) SDK, you can write code in the programming language of your choice. AWS SDK supports many popular programming languages.
For web technology it supports, such as Java, Javascript, Python, PHP, .net, Go, etc.
For Mobile technology, it supports Android, IOS, etc
For IoT devices it supoorts Embedded C, Ardunio, etc.
You can build a variety of projects like Upload and Download data from AWS S3, Launch, Stop, and Manage your EC2 instances, and Use AWS SNS for a mobile app to send notifications to 100s of users.
A good example is:- AWS CLI is built on AWS SDK for python.
Now let's look at how you can access AWS using AWS SDK.
In this tutorial, I'm going to use Nodejs. You can choose any programming language you want.
Create a new directory for your project and navigate to your project:
mkdir aws-sdk
cd aws-sdk
Initialize a new Node.js project:
npm init -y
This will create a package.json file in your project directory.Create a new file called
app.js
in your project directory:
touch app.js
Now, you will need to install the AWS SDK and Dotenv(For accessing environment variables) packages for Node.js by running the following command in your terminal:
npm install aws-sdk dotenv
Open the
app.js
file in your text editor and add the following code:// Load the AWS SDK for Node.js var AWS = require("aws-sdk"); require("dotenv").config(); AWS.config.update({ region: "ap-south-1", maxRetries: 3, httpOptions: { timeout: 30000, connectTimeout: 5000 }, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }); console.log(process.env.AWS_ACCESS_KEY_ID); var iam = new AWS.IAM(); var params = { MaxItems: 10, }; iam.listUsers(params, function (err, data) { if (err) { console.log("Error", err); } else { var users = data.Users || []; users.forEach(function (user) { // Print List of Users console.log(user); }); } })
This will return an array of User objects, each of which contains information about a single IAM user.
You can now use the data as per your requirements.
NOTE:- You need to store Access & SECRET KEY as an environment variable in the .env file
AWS SDK is very helpful when you have to do repetitive tasks again and again. All you need to do is to Create an automation task and let the AWS SDK will handle it. So you can focus on scaling, securing, and distributing your AWS infrastructure.
Additionally, AWS SDK provides comprehensive and up-to-date documentation, code samples, and tools, which help you to get the most out of AWS services. Whether you are just starting to build a new application or integrating with an existing one, AWS SDK is an important software kit for accessing any AWS service programmatically.
There are many use cases where AWS SDK is valuable, but to make it simple and easy to understand I added a few examples this helps you to get started with AWS SDK.
You can also clone my GitHub repo for the AWS SDK Demo. If you are just lazy as me to write the same code again and again.
BONUS 🎁
Programmers love to use CLI most of the time. Because it takes fewer resources, doesn't have to do a repetitive task, has high precision, and is powerful. You can use the same CLI directly in the AWS management console. In AWS you can use Powerful CLI right from your browser without configuring CLI Tool.
Yes, AWS provides AWS CloudShell that you can use directly from any browser. For CLI you need to download the tool to use the power of CLI Commands but using AWS CloudShell you can directly use the power of CLI directly.
With AWS CloudShell, you can access the resources in your chosen AWS region with a command-line interface. AWS CloudShell comes pre-installed with popular tools for resource management and creation.
Pre-install Tools like Nodejs, Python, AWS CLI, and more.
Storage included 1 GB of storage free per AWS region.
In future sessions for the same AWS region, settings and files saved in your home directory will be available.
NOTE:- AWS CloudShell is not available for every region. Using this link, you can find out in which region AWS CloudShell is available.
Here are the steps, How you can access AWS CloudShell.
Login to your AWS Account and go to your AWS Management console, In the console, you can see the CLI Icon at the top right side before the notification bell icon Click on the CLI Icon. Make sure you select the region which has AWS CloudShell available.
It will open AWS CloudShell, You can use all the CLI commands directly from your browser.
If you are working in a CLI terminal then AWS CloudShell is a good option for you. Many Engineers/Developers prefer AWS CloudShell. You can use it as per your requirement and needs. AWS CloudShell is a good alternative to AWS CLI. No need to Install, or configure anything. Just use the CLI feature using the browser instantly.
Conclusion
Good Job 👍, Congratulations on getting this far 🎉! Now pat yourself on the back. In this blog tutorial, You have learned how to access AWS. Depending on your preference you use any of the ways to access AWS.
Usually, I access AWS through the management console & CloudShell most of the time. How are you going to access AWS? Tell me in the comment below. 👇
I’m going to share more content on the cloud and make it easy for you to understand complex cloud services.
So, please follow me, Feel free to comment and share your suggestions/thoughts.
Also, Follow me on Twitter @asenseofpradhyu. I share daily Cloud, System Design, Code, and many more tech stuff 😊