본문 바로가기

AWS

aws - cli - 실습 과정

728x90

 

Microsoft Windows [Version 10.0.22631.3880]
(c) Microsoft Corporation. All rights reserved.

C:\Users\admin>aws configure
AWS Access Key ID [None]:  khsid
AWS Secret Access Key [None]: khsacceskey
Default region name [None]: ap-northeast-2
Default output format [None]: json

C:\Users\admin>aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************RONK shared-credentials-file
secret_key     ****************RWoM shared-credentials-file
    region           ap-northeast-2      config-file    ~/.aws/config

C:\Users\admin>aws ec2 create-key-pair --key-name khs-cli-key-pair --key-type rsa --
key-format pem --query "KeyMaterial" --output text > khsCliKeyPair.pem

C:\Users\admin>aws ec2 describe-key-pairs
{
    "KeyPairs": [
        {
            "KeyPairId": "key-080e38a2fa32cd84c",
            "KeyFingerprint": "9f:02:dd:6e:50:fc:8a:1b:82:bb:c1:0e:3e:e1:66:d7:ea:dd:a7:a7",
            "KeyName": "key-0710",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-10T05:06:05.450000+00:00"
        },
        {
            "KeyPairId": "key-01d812bad7f07284c",
            "KeyFingerprint": "84:02:6e:f2:91:5d:2f:b5:de:9e:e8:17:94:65:55:c1:bb:9e:e4:e7",
            "KeyName": "khsed22519pemtest",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-18T04:48:30.555000+00:00"
        },
        {
            "KeyPairId": "key-0e2434b024d530796",
            "KeyFingerprint": "07:f0:3d:20:c6:61:d8:34:7b:07:ff:08:b3:a9:81:a1:4f:01:e5:65",
            "KeyName": "test",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-09T06:26:37.367000+00:00"
        },
        {
            "KeyPairId": "key-03d67b2739af43ab5",
            "KeyFingerprint": "d8:d6:d4:49:ac:c6:dc:d7:8a:98:46:b3:bb:1f:5c:a0:1f:0b:97:f2",
            "KeyName": "keypair719",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-19T01:43:35.892000+00:00"
        },
        {
            "KeyPairId": "key-0a7cdab9ea7737f80",
            "KeyFingerprint": "97:20:c0:18:64:36:52:13:56:e4:4b:31:18:dc:c5:db:08:8e:5c:2b",
            "KeyName": "khsrsappktest",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-18T04:51:43.666000+00:00"
        },
        {
            "KeyPairId": "key-003f333773ec64ae5",
            "KeyFingerprint": "e9:f6:7d:29:3d:69:55:3c:b1:20:19:aa:1f:6d:b5:3d:42:b9:79:c5",
            "KeyName": "khstest",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-18T05:14:37.184000+00:00"
        },
        {
            "KeyPairId": "key-01993bcaf34a07149",
            "KeyFingerprint": "4e:37:b9:4f:d3:05:47:1c:93:38:a5:7d:2a:3c:95:ac:c5:2c:b3:c9",
            "KeyName": "khstest2",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-18T05:18:12.408000+00:00"
        },
        {
            "KeyPairId": "key-07830ab25ad445afb",
            "KeyFingerprint": "6f:47:95:0f:17:23:af:5f:e2:5f:34:97:11:16:d5:38:4f:de:ae:04",
            "KeyName": "khs-cli-key-pair",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-28T12:55:12.652000+00:00"
        },
        {
            "KeyPairId": "key-047d723675875ab8a",
            "KeyFingerprint": "55:fc:d3:da:99:5a:b0:32:80:05:2e:23:4b:57:bc:cf:81:7a:2d:62",
            "KeyName": "khsrsapemtst",
            "KeyType": "rsa",
            "Tags": [],
            "CreateTime": "2024-07-18T04:43:36.606000+00:00"
        },

C:\Users\admin>aws ec2 create-security-group --group-name khs-study-group --descript
ion "for-aws-cli-strudy"

An error occurred (VPCIdNotSpecified) when calling the CreateSecurityGroup operation: No default VPC for this user

C:\Users\admin>aws ec2 create-security-group --group-name khs-study-group --description

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

aws: error: argument --description: expected one argument


C:\Users\admin>aws ec2 create-security-group --group-name khs-study-group --description "for-study"

An error occurred (VPCIdNotSpecified) when calling the CreateSecurityGroup operation: No default VPC for this user

C:\Users\admin>aws ec2 create-security-group --group-name front-end-hs --description
 "front-hs"

An error occurred (VPCIdNotSpecified) when calling the CreateSecurityGroup operation: No default VPC for this user

C:\Users\admin>aws ec2 describe-vpcs --query "Vpcs[*].{ID:VpcId, State:State, CIDR:CidrBlock}"
[
    {
        "ID": "vpc-077e1bca2432f062a",
        "State": "available",
        "CIDR": "10.0.0.0/16"
    },
    {
        "ID": "vpc-0d3db4beffa345b39",
        "State": "available",
        "CIDR": "100.123.0.0/16"
    },
    {
        "ID": "vpc-050496fd3d9ad1ee8",
        "State": "available",
        "CIDR": "172.0.0.0/16"
    }
]


C:\Users\admin>aws ec2 create-security-group --group-name khs-study-group --description "for-aws-cli-study" --vpc-id vpc-077e1bca2432f062a
{
    "GroupId": "sg-05b8f3006a7020ebd"
}


C:\Users\admin>aws ec2 run-instances --image-id ami-045f2d6eeb07ce8c0 --count 1 --instance-type t2.micro --key-name khs-cli-key-pair --security-group-ids sg-05b8f3006a7
020ebd

An error occurred (VPCIdNotSpecified) when calling the RunInstances operation: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.

C:\Users\admin>aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-077e1bca2432f062a" --query "Subnets[*].{ID:SubnetId}"
[
    {
        "ID": "subnet-076450fa2b2592b55"
    },
    {
        "ID": "subnet-0ca9828cfd1c0a023"
    }
]


C:\Users\admin>aws ec2 run-instances --image-id ami-045f2d6eeb07ce8c0 --count 1 --instance-type t2.micro --key-name khs-cli-key-pair --security-group-ids sg-05b8f3006a7020ebd --subnet-id subnet-076450fa2b2592b55
{
    "Groups": [],
    "Instances": [
        {
            "AmiLaunchIndex": 0,
            "ImageId": "ami-045f2d6eeb07ce8c0",
            "InstanceId": "i-087adeea0e57ac01f",
            "InstanceType": "t2.micro",
            "KeyName": "khs-cli-key-pair",
            "LaunchTime": "2024-07-28T13:12:08+00:00",
            "Monitoring": {
                "State": "disabled"
            },
            "Placement": {
                "AvailabilityZone": "ap-northeast-2a",
                "GroupName": "",
                "Tenancy": "default"
            },
            "PrivateDnsName": "ip-10-0-0-178.ap-northeast-2.compute.internal",
            "PrivateIpAddress": "10.0.0.178",
            "ProductCodes": [],
            "PublicDnsName": "",
            "State": {
                "Code": 0,
                "Name": "pending"
            },
            "StateTransitionReason": "",
            "SubnetId": "subnet-076450fa2b2592b55",
            "VpcId": "vpc-077e1bca2432f062a",
            "Architecture": "x86_64",
            "BlockDeviceMappings": [],
            "ClientToken": "247485c8-254f-4164-b612-ee69eafbd1b1",
            "EbsOptimized": false,
            "EnaSupport": true,
            "Hypervisor": "xen",
            "NetworkInterfaces": [
                {
                    "Attachment": {
                        "AttachTime": "2024-07-28T13:12:08+00:00",
                        "AttachmentId": "eni-attach-0c33fa0e9855aef27",
                        "DeleteOnTermination": true,
                        "DeviceIndex": 0,
                        "Status": "attaching",
                        "NetworkCardIndex": 0
                    },
                    "Description": "",
                    "Groups": [
                        {
                            "GroupName": "khs-study-group",
                            "GroupId": "sg-05b8f3006a7020ebd"
                        }
                    ],
                    "Ipv6Addresses": [],
                    "MacAddress": "02:50:d1:18:46:2f",
                    "NetworkInterfaceId": "eni-09735992acc9cb8c5",
                    "OwnerId": "018067032425",
                    "PrivateDnsName": "ip-10-0-0-178.ap-northeast-2.compute.internal",
                    "PrivateIpAddress": "10.0.0.178",
                    "PrivateIpAddresses": [
                        {
                            "Primary": true,
                            "PrivateDnsName": "ip-10-0-0-178.ap-northeast-2.compute.internal",
                            "PrivateIpAddress": "10.0.0.178"
                        }
                    ],
                    "SourceDestCheck": true,
                    "Status": "in-use",
                    "SubnetId": "subnet-076450fa2b2592b55",
                    "VpcId": "vpc-077e1bca2432f062a",
                    "InterfaceType": "interface"
                }
            ],
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "SecurityGroups": [
                {
                    "GroupName": "khs-study-group",
                    "GroupId": "sg-05b8f3006a7020ebd"
                }
            ],
            "SourceDestCheck": true,
            "StateReason": {
                "Code": "pending",
                "Message": "pending"
            },
            "VirtualizationType": "hvm",
            "CpuOptions": {
                "CoreCount": 1,
                "ThreadsPerCore": 1
            },
            "CapacityReservationSpecification": {
                "CapacityReservationPreference": "open"
            },
            "MetadataOptions": {
                "State": "pending",
                "HttpTokens": "required",
                "HttpPutResponseHopLimit": 2,
                "HttpEndpoint": "enabled",
                "HttpProtocolIpv6": "disabled",
                "InstanceMetadataTags": "disabled"
            },
            "EnclaveOptions": {
                "Enabled": false
            },
            "BootMode": "uefi-preferred",
            "PrivateDnsNameOptions": {
                "HostnameType": "ip-name",
                "EnableResourceNameDnsARecord": false,
                "EnableResourceNameDnsAAAARecord": false
            },
            "MaintenanceOptions": {
                "AutoRecovery": "default"
            },
            "CurrentInstanceBootMode": "legacy-bios"
        }
    ],
    "OwnerId": "018067032425",
    "ReservationId": "r-04d42de148d8a84da"
}


C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>ssh -i khs-key-pair.pen hs.kwan@okestro.com
Warning: Identity file khs-key-pair.pen not accessible: No such file or directory.

C:\Users\admin>aws ec2 run-instances --image-id ami-045f2d6eeb07ce8c0 --count 1 --instance-type t2.micro --key-name khs-cli-key-pair --security-group-ids sg-05b8f3006a7020ebd --subnet-id subnet-076450fa2b2592b55
{
    "Groups": [],
    "Instances": [
        {
            "AmiLaunchIndex": 0,
            "ImageId": "ami-045f2d6eeb07ce8c0",
            "InstanceId": "i-04b5c66a2d8e8976a",
            "InstanceType": "t2.micro",
            "KeyName": "khs-cli-key-pair",
            "LaunchTime": "2024-07-28T13:16:57+00:00",
            "Monitoring": {
                "State": "disabled"
            },
            "Placement": {
                "AvailabilityZone": "ap-northeast-2a",
                "GroupName": "",
                "Tenancy": "default"
            },
            "PrivateDnsName": "ip-10-0-4-182.ap-northeast-2.compute.internal",
            "PrivateIpAddress": "10.0.4.182",
            "ProductCodes": [],
            "PublicDnsName": "",
            "State": {
                "Code": 0,
                "Name": "pending"
            },
            "StateTransitionReason": "",
            "SubnetId": "subnet-076450fa2b2592b55",
            "VpcId": "vpc-077e1bca2432f062a",
            "Architecture": "x86_64",
            "BlockDeviceMappings": [],
            "ClientToken": "24d3a38c-07f9-40fd-a5b5-3412d3e80317",
            "EbsOptimized": false,
            "EnaSupport": true,
            "Hypervisor": "xen",
            "NetworkInterfaces": [
                {
                    "Attachment": {
                        "AttachTime": "2024-07-28T13:16:57+00:00",
                        "AttachmentId": "eni-attach-0713c52c090f789f1",
                        "DeleteOnTermination": true,
                        "DeviceIndex": 0,
                        "Status": "attaching",
                        "NetworkCardIndex": 0
                    },
                    "Description": "",
                    "Groups": [
                        {
                            "GroupName": "khs-study-group",
                            "GroupId": "sg-05b8f3006a7020ebd"
                        }
                    ],
                    "Ipv6Addresses": [],
                    "MacAddress": "02:f3:a1:68:c1:c7",
                    "NetworkInterfaceId": "eni-05346dd55326c2d6f",
                    "OwnerId": "018067032425",
                    "PrivateDnsName": "ip-10-0-4-182.ap-northeast-2.compute.internal",
                    "PrivateIpAddress": "10.0.4.182",
                    "PrivateIpAddresses": [
                        {
                            "Primary": true,
                            "PrivateDnsName": "ip-10-0-4-182.ap-northeast-2.compute.internal",
                            "PrivateIpAddress": "10.0.4.182"
                        }
                    ],
                    "SourceDestCheck": true,
                    "Status": "in-use",


C:\Users\admin>ssh -i khs-key-pair.pem hs.kwan@okestro.com
Warning: Identity file khs-key-pair.pem not accessible: No such file or directory.

C:\Users\admin>
C:\Users\admin>
C:\Users\admin>
C:\Users\admin>

 

지피티 q/a-url : https://chatgpt.com/c/f5e1f7d5-9977-47ac-91dd-584e520a701e

 

 

 

  1. aws configure: AWS CLI를 설정하는 명령어입니다. 실행하면 AWS 액세스 키, 비밀 액세스 키, 기본 리전 이름 및 출력 형식을 입력하라는 프롬프트가 나타납니다. 이를 통해 AWS 자원에 대한 접근 권한을 설정합니다.
  2. aws configure list: 현재 설정된 AWS CLI 구성 정보를 나열합니다. 여기에는 AWS 액세스 키, 기본 리전, 출력 형식 등이 포함됩니다.
  3. aws ec2 describe-key-pairs: 사용자가 소유한 EC2 키 페어를 나열합니다. 키 페어는 EC2 인스턴스에 안전하게 연결하기 위한 SSH 키 쌍입니다.
  4. aws ec2 create-security-group --group-name front-end-hs --description "front-hs": front-end-hs라는 이름과 "front-hs"라는 설명으로 보안 그룹을 생성합니다.
  5. aws ec2 describe-vpcs --query "Vpcs[*].{ID:VpcId, State:State, CIDR:CidrBlock}": 계정에 있는 모든 VPC (Virtual Private Cloud)를 나열하고 각 VPC의 ID, 상태 및 CIDR 블록을 표시합니다.
  6. aws ec2 create-security-group --group-name khs-study-group --description "for-aws-cli-study" --vpc-id vpc-077e1bca2432f062a: 특정 VPC (vpc-077e1bca2432f062a)에 속하는 보안 그룹을 생성합니다. 이 보안 그룹의 이름은 khs-study-group이고, 설명은 "for-aws-cli-study"입니다.
  7. aws ec2 run-instances --image-id ami-045f2d6eeb07ce8c0 --count 1 --instance-type t2.micro --key-name khs-cli-key-pair --security-group-ids sg-05b8f3006a7020ebd: AMI ID가 ami-045f2d6eeb07ce8c0인 이미지로부터 t2.micro 타입의 인스턴스를 하나 실행합니다. 이 인스턴스는 khs-cli-key-pair라는 키 페어를 사용하며, sg-05b8f3006a7020ebd 보안 그룹에 속합니다.
  8. aws ec2 run-instances --image-id ami-045f2d6eeb07ce8c0 --count 1 --instance-type t2.micro --key-name khs-cli-key-pair --security-group-ids sg-05b8f3006a7020ebd --subnet-id subnet-076450fa2b2592b55: 특정 서브넷 (subnet-076450fa2b2592b55)에 인스턴스를 배포하도록 지정합니다.

 

 

728x90

'AWS' 카테고리의 다른 글

AWS - 실습 - AWS Console EC2 생성 과정  (0) 2024.07.28