⚜AWS Command Line Interface-Task
Hello Friends😊 , today we are going to complete a intresting task of AWS CLI 🤩
🔰Task Description- AWS 🤩🤩
🔅 Create a key pair
🔅 Create a security group
🔅 Launch an instance using the above created key pair and security group.
🔅 Create an EBS volume of 1 GB.
🔅 The final step is to attach the above created EBS volume to the instance you created in the previous steps.
🔰What is AWS CLI ❔❓
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
The AWS CLI introduces a new set of simple file commands for efficient file transfers to and from Amazon S3.
🔰Prerequisites
Before you can install or update the AWS CLI version 2 on Windows, be sure you have the following:
- A 64-bit version of Windows XP or later.
- Admin rights to install software
🔰Install or update the AWS CLI version 2 on Windows using the MSI installer
- Download the AWS CLI MSI installer for Windows (64-bit):
- For the latest version of the AWS CLI: https://awscli.amazonaws.com/AWSCLIV2.msi
- For a specific version of the AWS CLI: Append a hyphen and the version number to the filename. For this example the filename for version 2.0.30 would be AWSCLIV2-2.0.30.msi resulting in the following link https://awscli.amazonaws.com/AWSCLIV2-2.0.30.msi.
To update your current installation of AWS CLI version 2 on Windows, download a new installer each time you update to overwrite previous versions. AWS CLI is updated regularly.
2. Run the downloaded MSI installer and follow the on-screen instructions. By default, the AWS CLI installs to C:\Program Files\Amazon\AWSCLIV2.
3. To confirm the installation, open the Start menu, search for cmd to open a command prompt window, and at the command prompt use the aws -- version command.
4.Don’t include the prompt symbol (C:\>) when you type a command. These are included in program listings to differentiate commands that you type from output returned by the AWS CLI. The rest of this guide uses the generic prompt symbol ($), except in cases where a command is Windows-specific. For more information about how we format code examples, see Using the examples.
C:\> aws --version aws-cli/2.0.47 Python/3.7.4 Windows/10 botocore/2.0.0
If Windows is unable to find the program, you might need to close and reopen the command prompt window to refresh the path, or add the installation directory to your PATH environment variable manually.
🔰configuration with aws configure
For general use, the aws configure command is the fastest way to set up your AWS CLI installation. When you enter this command, the AWS CLI prompts you for four pieces of information:
The AWS CLI stores this information in a profile (a collection of settings) named default in the credentials file. By default, the information in this profile is used when you run an AWS CLI command that doesn't explicitly specify a profile to use. For more information on the credentials file, see Configuration and credential file settings
The following example shows sample values. Replace them with your own values as described in the following sections.
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: ap-south-1a Default output format [None]: json
🔰Access key ID and secret access key
Access keys consist of an access key ID and secret access key, which are used to sign programmatic requests that you make to AWS. If you don’t have access keys, you can create them from the AWS Management Console. As a best practice, do not use the AWS account root user access keys for any task where it’s not required. Instead, create a new administrator IAM user with access keys for yourself.
The only time that you can view or download the secret access key is when you create the keys. You cannot recover them later. However, you can create new access keys at any time. You must also have permissions to perform the required IAM actions. For more information, see Permissions Required to Access IAM Resources in the IAM User Guide.
🔰To create access keys for an IAM user
- Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
- In the navigation pane, choose Users.
- Choose the name of the user whose access keys you want to create, and then choose the Security credentials tab.
- In the Access keys section, choose Create access key.
- To view the new access key pair, choose Show. You will not have access to the secret access key again after this dialog box closes. Your credentials will look something like this:
- Access key ID: AKIAIOSFODNN7EXAMPLE
- Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- To download the key pair, choose Download .csv file. Store the keys in a secure location. You will not have access to the secret access key again after this dialog box closes.
- Keep the keys confidential in order to protect your AWS account and never email them. Do not share them outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your secret key.
- After you download the .csv file, choose Close. When you create an access key, the key pair is active by default, and you can use the pair right away.
Here we can see our IAM user “awscliuser1”sucessfully created🤩🤩 .
🔰Region
The Default region name identifies the AWS Region whose servers you want to send your requests to by default. This is typically the Region closest to you, but it can be any Region. For example, you can type us-west-2 to use US West (Oregon). This is the Region that all later requests are sent to, unless you specify otherwise in an individual command.
🔰Output format
The Default output format specifies how the results are formatted. The value can be any of the values in the following list. If you don't specify an output format, json is used as the default.
- json — The output is formatted as a JSON string.
- yaml — The output is formatted as a YAML string. (Available in the AWS CLI version 2 only.)
- yaml-stream — The output is streamed and formatted as a YAML string. Streaming allows for faster handling of large data types. (Available in the AWS CLI version 2 only.)
- text — The output is formatted as multiple lines of tab-separated string values. This can be useful to pass the output to a text processor, like grep, sed, or awk.
- table — The output is formatted as a table using the characters +|- to form the cell borders. It typically presents the information in a “human-friendly” format that is much easier to read than the others, but not as programmatically useful.
👉Now we can login to AWS using security credentials of IAM user we created .To login to AWS through AWS CLI we have command as “aws configure” .After running these command once we have to give AWS Access Key , Secret Access Key and Region Name .
aws configure
👉To Download the Key Pair .pem file we have to use following command which pipe the key pair into the file .
👉Now we successfully logged in to AWS Account From Command Prompt with CLI 🤩🤩. After that we have to Create Private Key to connect to the ec2 instance . for creating Key Pair we have command
aws create-key-pair --key-name key_name --query "awscliuser" >key_name.pem
👉To Create Security group we have the command as :
aws ec2 create-security-group --group-name group_name --description "_description_"
👉Friends , To check weather the security group is created or not used the AWS Management Console...
👉Now, To launch an instance using the above Key Pair & Security Group. To launch ec2 instance with AWS CLI has command as :
aws ec2 run-instance --security-group-ids group_id --instance-type _type_ --image-id ami_id --key-name key_name --count no_of_instance
👉we can check from AWS Management Console ....
👉After launching EC2 Instance now we have to Create EBS Volume of 1GB size and attach it to EC2 Instance that we launched .
👉To Create Ebs Volume AWS CLI has command as:
aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name
👉To Attach EBS Volume to EC2 Instance we have command :
aws ec2 attach-volume --volume-id vol-0fb363130a89fcc6f --instance-id i-01474ef662b89480 --device /dev/sdf
👉we can check from AWS Management Console ....
👉At last we have to Terminate the EC2 Instance before that we have have to Detached the EBS Volume using command :
aws ec2 detach-volume --volume-id volume_id
👉To Terminate the EC2 Instance use command as :
aws ec2 terminate-instances --instance-ids instance_id
👉we can check from AWS Management Console...
⚜ Hope Article will contribute to give some basic Knowledge of AWS CLI through the above task ❗❗❗❗ ⚜
✨Thanks for Your Precious Time 😃🤩
🔰 KEEP LEARNING ❗❗ 🔰 KEEP SHARING ❗❗
⚜WRITTEN BY : HARSHAL THAKARE
Well done Harshal Thakare 😄✌🏻
Great Harshal Thakare 🔥