AWS CLI
Configure your CLI after installing it in your computer.
Use command $aws configure
- * Don’t share these credentials with anyone **
- ** If you don’t know how to use AWS services or how to give particular parameters to the commands then you can use help at the end of the command.**
Use command $aws ec2 help
1 Create a key pair using aws cli-
Key pair-Creates a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key and displays the private key for you to save to a file. The private key is returned as an unencrypted PEM encoded PKCS#1 private key. If a key with the specified name already exists, Amazon EC2 returns an error.
You can have up to five thousand key pairs per Region.The key pair returned to you is available only in the Region in which you create it. If you prefer, you can create your own key pair using a third-party tool and upload it to any Region using ImportKeyPair.
Synopsis:-
create-key-pair
— key-name <value>
[ — dry-run | — no-dry-run]
[ — tag-specifications <value>]
[ — cli-input-json | — cli-input-yaml]
[ — generate-cli-skeleton <value>]
[ — cli-auto-prompt <value>]
Command used — $ aws ec2 create-key-pair — key-name arth3
Creating a security group:-
Creating a security group:-
A security group acts as a virtual firewall for your instance to
control inbound and outbound traffic. For more information, see Amazon
EC2 Security Groups in the *Amazon Elastic Compute Cloud User Guide*
and Security Groups for Your VPC in the *Amazon Virtual Private Cloud
User Guide* .
When you create a security group, you specify a friendly name of your
choice. You can have a security group for use in EC2-Classic with the
same name as a security group for use in a VPC. However, you can’t
have two security groups for use in EC2-Classic with the same name or
two security groups for use in a VPC with the same name.
You have a default security group for use in EC2-Classic and a default
security group for use in your VPC. If you don’t specify a security
group when you launch an instance, the instance is launched into the
appropriate default security group. A default security group includes
a default rule that grants instances unrestricted network access to
each other.
Synopsis:-
create-security-group
— description <value>
— group-name <value>
[ — vpc-id <value>]
[ — tag-specifications <value>]
[ — dry-run | — no-dry-run]
[ — cli-input-json | — cli-input-yaml]
[ — generate-cli-skeleton <value>]
[ — cli-auto-prompt <value>]
Command:-
$ aws ec2 create-security-group — group-name arth3 — description cli-task
Launch an instance:-
Launches the specified number of instances using an AMI for which you
have permissions.
You can specify a number of options, or leave the default options. The
following rules apply:
** [EC2-VPC] If you don’t specify a subnet ID, we choose a default
subnet from your default VPC for you. If you don’t have a default
VPC, you must specify a subnet ID in the request.
** [EC2-Classic] If don’t specify an Availability Zone, we choose one
for you.
** Some instance types must be launched into a VPC. If you do not have
a default VPC, or if you do not specify a subnet ID, the request
fails. For more information, see Instance types available only in a
VPC .
** [EC2-VPC] All instances have a network interface with a primary
private IPv4 address. If you don’t specify this address, we choose
one from the IPv4 range of your subnet.
** Not all instance types support IPv6 addresses. For more information,
see Instance types .
** If you don’t specify a security group ID, we use the default
security group. For more information, see Security groups .
** If any of the AMIs have a product code attached for which the user
has not subscribed, the request fails.
Synopsis:-
run-instances
[ — block-device-mappings <value>]
[ — image-id <value>]
[ — instance-type <value>]
[ — ipv6-address-count <value>]
[ — ipv6-addresses <value>]
[ — kernel-id <value>]
[ — key-name <value>]
[ — monitoring <value>]
[ — placement <value>]
[ — ramdisk-id <value>]
[ — security-group-ids <value>]
[ — security-groups <value>]
[ — subnet-id <value>]
[ — user-data <value>]
[ — additional-info <value>]
[ — client-token <value>]
[ — disable-api-termination | — enable-api-termination]
[ — dry-run | — no-dry-run]
[ — ebs-optimized | — no-ebs-optimized]
[ — iam-instance-profile <value>]
[ — instance-initiated-shutdown-behavior <value>]
[ — network-interfaces <value>]
[ — private-ip-address <value>]
[ — elastic-gpu-specification <value>]
[ — elastic-inference-accelerators <value>]
[ — tag-specifications <value>]
[ — launch-template <value>]
[ — instance-market-options <value>]
[ — credit-specification <value>]
[ — cpu-options <value>]
[ — capacity-reservation-specification <value>]
[ — hibernation-options <value>]
[ — license-specifications <value>]
[ — metadata-options <value>]
[ — count <value>]
[ — secondary-private-ip-addresses <value>]
[ — secondary-private-ip-address-count <value>]
[ — associate-public-ip-address | — no-associate-public-ip-address]
[ — cli-input-json | — cli-input-yaml]
[ — generate-cli-skeleton <value>]
[ — cli-auto-prompt <value>]
Command:-
$ aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id <value> — key-name arth3 — security-group-ids <value>
Creating Elastic Block Storage volume:-
Creates an EBS volume that can be attached to an instance in the same
Availability Zone. The volume is created in the regional endpoint that
you send the HTTP request to. For more information see Regions and
Endpoints .
You can create a new empty volume or restore a volume from an EBS
snapshot. Any AWS Marketplace product codes from the snapshot are
propagated to the volume.
You can create encrypted volumes. Encrypted volumes must be attached
to instances that support Amazon EBS encryption. Volumes that are
created from encrypted snapshots are also automatically encrypted.
Synopsis:-
create-volume
— availability-zone <value>
[ — encrypted | — no-encrypted]
[ — iops <value>]
[ — kms-key-id <value>]
[ — outpost-arn <value>]
[ — size <value>]
[ — snapshot-id <value>]
[ — volume-type <value>]
[ — dry-run | — no-dry-run]
[ — tag-specifications <value>]
[ — multi-attach-enabled | — no-multi-attach-enabled]
[ — cli-input-json | — cli-input-yaml]
[ — generate-cli-skeleton <value>]
[ — cli-auto-prompt <value>]
Command:-
$ aws ec2 create-volume — availability-zone ap-south-1a — no-encrypted — size 1
Attaching Elastic Block Storage volume:-
Attaches an EBS volume to a running or stopped instance and exposes it
to the instance with the specified device name.
Encrypted EBS volumes must be attached to instances that support
Amazon EBS encryption. For more information, see Amazon EBS Encryption
in the *Amazon Elastic Compute Cloud User Guide* .
After you attach an EBS volume, you must make it available. For more
information, see Making an EBS Volume Available For Use .
If a volume has an AWS Marketplace product code:
* The volume can be attached only to a stopped instance.
* AWS Marketplace product codes are copied from the volume to the
instance.
* You must be subscribed to the product.
- The instance type and operating system of the instance must support
the product. For example, you can’t detach a volume from a Windows
instance and attach it to a Linux instance.
Synopsis:-
attach-volume
— device <value>
— instance-id <value>
— volume-id <value>
[ — dry-run | — no-dry-run]
[ — cli-input-json | — cli-input-yaml]
[ — generate-cli-skeleton <value>]
[ — cli-auto-prompt <value>]
Command:-
$ aws ec2 attach-volume — instance-id <value>— volume-id <value>— device sdf