Launch Some Service Of AWS with AWS-CLI

Prince Prashant Saini
8 min readNov 4, 2020

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.

All the above steps must be performed using AWS CLI

Solution 🗼

First we have start with IAM user . Create a IAM user

IAM

An AWS Identity and Access Management (IAM) user is an entity that you create in AWS to represent the person or application that uses it to interact with AWS. A user in AWS consists of a name and credentials.
An IAM user with administrator permissions is not the same thing as the AWS account root user. For more information about the root user, see AWS account root user.

How to Create IAM 🤷‍♂️

Go to👇

👉Here Register if not if yes then login
👉After login you have to see AWS portal like this 👇

After Login select Services in to top left side after it scroll down and find Security, Identity, & Compliance here one service of IAM 👇

open IAM user Here we have see this type of portal👇 here click on Users and after it at top in blue box we have Add user click add user

After add user we have first 👇

👉User name = here we have give any name we have give princeprashantsaini1
👉Access Type = > we have give both Programmatic access for launch with aws cli
👉AWS Management Console access = login for GUI
👉Console Password => give for login in AWS Console 👇

Now click Next: Permissions

Now give Give Permissions
here we give AdministratorAccess (we have give full admin power to it)

then Next: Tags

we have not give any tags we have next we have check all condition then last create user

Now we have key download as .csv that use in AWS-CLI

Now close and check User created or not

Now user created 🤘

AWS-CLI

It is CLI version of AWS.

How to install🤷‍♂️

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

  1. Download the AWS CLI MSI installer for Windows (64-bit):

For the latest version of the AWS CLI: https://awscli.amazonaws.com/AWSCLIV2.msi

  1. 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. To see when the latest version was released, see the AWS CLI version 2 changelog on GitHub.
  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.

Uninstall the AWS CLI version 2 from Windows

  1. Open Programs and Features by doing one of the followings
  • Open the Control Panel, and then choose Programs and Features.
  • Open a command prompt, and then enter the following command.

C:\> appwiz.cpl

  1. Select the entry named AWS Command Line Interface, and then choose Uninstall to launch the uninstaller.

2. Confirm that you want to uninstall the AWS CLI.

Now Cli setup done 🤘

Now our setup ready to start task work🗼

Key Pair

A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances. Anyone who possesses your private keys can connect to your instances, so it’s important that you store your private keys in a secure place.

First we have Run

aws configure

give all Access Key and Secrete Key given by IAM user and region ap-south-1

then Create a key with aws-cli

aws ec2 create-key-pair — key-name awskey

Now key is created let confirm with AWS GUI it created on AWS console or not 🤷‍♂️

yes it created 👆

Security Group

A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance. When you launch an instance, you can specify one or more security groups. If you don’t specify a security group, Amazon EC2 uses the default security group. You can add rules to each security group that allow traffic to or from its associated instances. You can modify the rules for a security group at any time. New and modified rules are automatically applied to all instances that are associated with the security group. When Amazon EC2 decides whether to allow traffic to reach an instance, it evaluates all of the rules from all of the security groups that are associated with the instance.

For security Group we use this command

aws ec2 create-security-group — description “security Group” — group-name “sg1” — vpc-id vpc-1095767b

check in GUI it created or not 🤷‍♂️

Now it created 🤘

EC2

Amazon Elastic Compute Cloud (EC2) is a part of Amazon.com’s cloud-computing platform, Amazon Web Services (AWS), that allows users to rent virtual computers on which to run their own computer applications. EC2 encourages scalable deployment of applications by providing a web service through which a user can boot an Amazon Machine Image (AMI) to configure a virtual machine, which Amazon calls an “instance”, containing any software desired. A user can create, launch, and terminate server-instances as needed, paying by the second for active servers — hence the term “elastic”. EC2 provides users with control over the geographical location of instances that allows for latency optimization and high levels of redundancy. In November 2010, Amazon switched its own retail website platform to EC2 and AWS

Launch EC2 instance use of this security Group and Key pair

first check in GUI we have a instance or not

There is no instance so we have launch in CMD

aws ec2 run-instances — image-id ami-052c08d70def0ac62 — instance-type t2.micro — subnet-id subnet-0d9fe141 — security-group-ids sg-00eff9348ff1arf31 — key-name awskey

Now we have see it created in GUI or not

Yes it created 🤘

EBS

Amazon Elastic Block Store (EBS) provides raw block-level storage that can be attached to Amazon EC2 instances and is used by Amazon Relational Database Service (RDS)
Amazon EBS provides a range of options for storage performance and cost. These options are divided into two major categories: SSD-backed storage for transactional workloads, such as databases and boot volumes (performance depends primarily on IOPS), and disk-backed storage for throughput intensive workloads, such as MapReduce and log processing (performance depends primarily on MB/s)

Create EBS and attached with our instance

aws ec2 attache-volume — instance-id i-00f44bcf2eed3688 — volume-id vol-06d400e6954eeca2d — device /dev/sda2

now it use by our instance now all step done with AWS-cli 🤘🤘

🙏🙏🙏THANKS🙏🙏🙏

--

--