Dear Readers,
In this article, we will see the following Create Amazon Linux EC2 Instance in AWS CLI.
Steps to Follow :
- Connect to AWS CLI On Windows
- Create a Key Pair
- Create a Security Group
- Create a Amazon EC2 Instance
- Create a Volume
- Attach volume to ec2 Instance
1. Connect to AWS CLI On Windows
To configure AWS CLI On Windows click here
Go inside the Command Line Interface
Specify required credentials, region and output format for connect to AWS CLI
1 2 3 4 5 |
C:\Users\user>aws configure AWS Access Key ID [None]: AKIAIGUQ7POGL3A6I3GQ AWS Secret Access Key [None]: 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 Default region name [None]: ap-south-1 Default output format [None]: table |
2. Create Key Pair
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
C:\Users\user>aws ec2 create-key-pair --key-name ktexperts_key { "KeyFingerprint": "ea:8e:97:2b:61:c0:bd:02:38:7b:f5:a3:28:3e:0f:c7:b2:62:97:82", "KeyMaterial": "-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAoQQaHEnGi2aau2tKAEGmFcr+rdiA6tyFCGvVWAFE1Qqn6KzQ 8IuIT/+FMNH/wu+cpxXehszXXzl3NWdyhnQ6cL1J3dzHYQHyCfE3SJjUnUm9gcq7 FQm4RLTrcMJ1PUqc+FDebpxHEzYGuj4OE46ge1I5M61TL1NeEACCexo1wwnf11f/ cG8sE7xbZRi/abO+EL3U1brjkoZXABJoz6rDa6lSJoEYpu7WIg+LkrrouXl7ACb8 xZYEcT/3IufSqbqQAwWsWW9WRowbAmox0qOEu7vYAC8d1lzzCYV6aPp4/0jH90jE ATe3CV2dzGnCtljAKALJq7rA6MbiPdzwd/PwzQIDAQABAoIBABK05UuwDo8XhpaL qndJKUCS6u/LnX6rzBDkZk7pJtQRftx7Z3Lq4xVYPGMloq9FI1AOLGJA3izEAmOD 9zxDuJ5sf251Pfy5OyOIkMGwb9MuRAQWR5H0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qa3CtfR6dMmZttSJPmZjn3CpMTKoPi8Jt3tANrRrkX\neFIxU/QTRjuRN excOfsJbd1WnMiJUm41g7IyNcjn3JNYqjkumHJzFN5oH8DLU30P\nfA2BlSapzkOA8ya UvGIz7y1SXgq/mfn8wVg0tgRyN1g0RshpdvCvk4b0LJ5mLR3H\n62Pk6P0b/Dvqa29Bb /F38lh3XERYwAfxQFWdZhECgYEAxD68GPJy+QNMVkoMznWX\ndAT9qWRCHhwdibXrtVI Sjd2kV8IZgaD7zKM5wrTeIw2YFQmVBtlbA+jY25btKAkc\nrbh/rUxiteC09oz3D9kX4 8GXo3C/oMW1QlzO4izMG3wu8cERGSnqSfmSZuAKZUBo\nFYyDM1XEvF2zkypecCnmG3M CgYEAncssncv+apFEKmfQ0Jibn7Z81kxBcCrGcNy0\nNAkx23Q8CDUtrErYOHxBalzoN 1IPaxSE00Q2GBvt2ir/RHEBRxcModt2Gzh96txi\nk0jDmWxj/3XnFol3g1CWiEsH/z0 1puWeUZQN6ql4BLv6lGhSAIETLUVjfLB14ZH\n2ygkZYECgYAGt1j9h0Y6CDSf/WdlzL 0KSJKcj7K5fCTzMNAOlIb787oVsoRCOXhY\nDui5tZkvnJFUOkHZ1r80WzCcyKXgwlGF vFZlMm+Mcd+3jnPSstwo7WXeVlmwPgMr\n2CkUsbaahM8F3RnIZihrPb38j3Ldurczyx QtzJGJg8+I8e9Rn90J6Q==\n-----END RSA PRIVATE KEY-----", "KeyName": "ktexperts_key", "KeyPairId": "key-040d0328ad262ec96" |
Verify Key Pair in graphical
3. Create a Security Group
1 2 3 4 |
C:\Users\user>aws ec2 create-security-group --group-name ktexperts --description "ktexperts" { "GroupId": "sg-0872608d936b3095e" } |
Verify in graphical
4. Create a Amazon EC2 Instance
Copy AMI of Amazon Linux2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
C:\Users\user>aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2 <a href ="https://ed-hrvatski.com/genericka-levitra/" style="color: #333; border-color: transparent; font-weight: normal; text-decoration: none">link za web stranicu</a>.micro --key-name ktexperts_key --security-group-ids sg-0872608d936b3095e { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0e306788ff2473ccb", "InstanceId": "i-0c60b86b4ea1f91f4", "InstanceType": "t2.micro", "KeyName": "ktexperts_key", "LaunchTime": "2020-10-15T06:51:44.000Z", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "ap-south-1a", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-172-31-36-36.ap-south-1.compute.internal", "PrivateIpAddress": "172.31.36.36", "ProductCodes": [], "PublicDnsName": "", "State": { "Code": 0, "Name": "pending" }, "StateTransitionReason": "", "SubnetId": "subnet-dad4c1b2", "VpcId": "vpc-dd12feb6", "Architecture": "x86_64", "BlockDeviceMappings": [], "ClientToken": "e8c3a6f4-b400-45ef-af09-1793546c2fcf", "EbsOptimized": false, "Hypervisor": "xen", "NetworkInterfaces": [ { "Attachment": { "AttachTime": "2020-10-15T06:51:44.000Z", "AttachmentId": "eni-attach-081855dc65adbf101", "DeleteOnTermination": true, "DeviceIndex": 0, "Status": "attaching" }, "Description": "", "Groups": [ { "GroupName": "ktexperts", "GroupId": "sg-0872608d936b3095e" } ], "Ipv6Addresses": [], "MacAddress": "02:bd:2c:dc:10:d6", "NetworkInterfaceId": "eni-0a7abb8bc0abaf331", "OwnerId": "740581369608", "PrivateDnsName": "ip-172-31-36-36.ap-south-1.compute.internal", "PrivateIpAddress": "172.31.36.36", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-172-31-36-36.ap-south-1.compute.internal", "PrivateIpAddress": "172.31.36.36" } ], "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-dad4c1b2", "VpcId": "vpc-dd12feb6", "InterfaceType": "interface" } ], "RootDeviceName": "/dev/xvda", "RootDeviceType": "ebs", "SecurityGroups": [ { "GroupName": "ktexperts", "GroupId": "sg-0872608d936b3095e" } ], "SourceDestCheck": true, "StateReason": { "Code": "pending", "Message": "pending" }, "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 1 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "MetadataOptions": { "State": "pending", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled" } } ], "OwnerId": "740581369608", "ReservationId": "r-060ad4b3b14c891e9" } |
Verify the Amazon EC2 Instance in graphical
5. Create a Volume
Before creating volume we need to check the availability zone your ec2 instance because ec2 instance and volume should be in same availability zone.
Verify Availability Zone
Create a Volume
1 2 3 4 5 6 7 8 9 10 11 12 13 |
C:\Users\user>aws ec2 create-volume --volume-type gp2 --size 5 --availability-zone ap-south-1a { "AvailabilityZone": "ap-south-1a", "CreateTime": "2020-10-15T06:53:32.000Z", "Encrypted": false, "Size": 5, "SnapshotId": "", "State": "creating", "VolumeId": "vol-00455377bc62599c8", "Iops": 100, "Tags": [], "VolumeType": "gp2" } |
Verify Volume in graphical
6. Attach volume to EC2 Instance
1 2 3 4 5 6 7 8 |
C:\Users\user>aws ec2 attach-volume --volume-id vol-00455377bc62599c8 --instance-id i-0c60b86b4ea1f91f4 --device /dev/sdf { "AttachTime": "2020-10-15T06:57:56.438Z", "Device": "/dev/sdf", "InstanceId": "i-0c60b86b4ea1f91f4", "State": "attaching", "VolumeId": "vol-00455377bc62599c8" } |
Verify in graphical
Thank you for giving your valuable time to read the above information.
Follow us on
Website : www.ktexperts.com
Facebook Page : KTexperts
Linkedin Page : KT EXPERTS
Follow Me
Ramesh’s Linkedin : Ramesh Atchala