Skip to content

Instantly share code, notes, and snippets.

@qrtt1
Last active August 29, 2015 13:56
Show Gist options
  • Save qrtt1/9110349 to your computer and use it in GitHub Desktop.
Save qrtt1/9110349 to your computer and use it in GitHub Desktop.

https://s3-ap-southeast-1.amazonaws.com/aa.iii.ddd/exam.rar

https://174078020804.signin.aws.amazon.com/console

AWS

  1. 服務首頁 http://aws.amazon.com/
  2. 服務節點 http://aws.amazon.com/cn/about-aws/global-infrastructure/

教材

短址:bitly.com/aws_intro

  1. 投影片 https://speakerdeck.com/qrtt1/aws-workshop-for-beginner
  2. 專欄 http://www.codedata.com.tw/author/qrtt1
  3. AWS USER Group https://www.facebook.com/groups/awsugtw/
  4. 帳單管理 http://www.codedata.com.tw/cloud/aws-tips-billing-management/

email: chingyi dot chan at gmail dot com

AWS URLs

  1. 首頁 http://aws.amazon.com/
  2. 文件 http://aws.amazon.com/documentation/
  3. SDK https://aws.amazon.com/tools/
  4. AWSCli http://aws.amazon.com/cli/

--

yum search httpd
sudo yum install httpd.x86_64
sudo service httpd start

awscli lab

設定檔範例:

config:

[default]
aws_access_key_id=
aws_secret_access_key=
region=ap-southeast-1

s3 cmd

例出 bucket

aws s3 ls

例 bucket 內的檔案

aws s3 ls s3://kj.abc.d

下載檔案

aws s3 cp s3://kj.abc.d/simple.png c:\

上傳檔案

aws s3 cp RESULT.TXT s3://kj.abc.d/

上傳檔案並指定 ACL public-read

aws s3 cp --acl public-read RESULT.TXT s3://kj.abc.d/ 

建立新機器

aws ec2 run-instances --image-id ami-a6b6eaf4 --instance-type t2.micro --count 1

輸出結果:

  1. 主要會使用到 InstanceId
  2. 可觀察 InstanceType 是否符合期望
  3. 可觀察 Key Pair 是否指定正確
  4. 可觀察 Security Group 是否指定正確
{
    "OwnerId": "174078020804",
    "ReservationId": "r-e5bdfbcd",
    "Groups": [],
    "Instances": [
        {
            "Monitoring": {
                "State": "disabled"
            },
            "PublicDnsName": null,
            "KernelId": "aki-503e7402",
            "State": {
                "Code": 0,
                "Name": "pending"
            },
            "EbsOptimized": false,
            "LaunchTime": "2014-03-19T15:38:54.000Z",
            "PrivateIpAddress": "172.31.22.237",
            "ProductCodes": [],
            "VpcId": "vpc-d83f8ab0",
            "StateTransitionReason": null,
            "InstanceId": "i-3c175414",
            "ImageId": "ami-b4baeee6",
            "PrivateDnsName": "ip-172-31-22-237.ap-southeast-1.compute.internal",
            "KeyName": "MyKeyPair",
            "SecurityGroups": [
                {
                    "GroupName": "MySecurityGroup",
                    "GroupId": "sg-c66383a9"
                }
            ],
            "ClientToken": null,
            "SubnetId": "subnet-da3f8ab2",
            "InstanceType": "t1.micro",
            "NetworkInterfaces": [
                {
                    "Status": "in-use",
                    "SourceDestCheck": true,
                    "VpcId": "vpc-d83f8ab0",
                    "Description": null,
                    "NetworkInterfaceId": "eni-4f0c153b",
                    "PrivateIpAddresses": [
                        {
                            "PrivateDnsName": "ip-172-31-22-237.ap-southeast-1.compute.internal",
                            "Primary": true,
                            "PrivateIpAddress": "172.31.22.237"
                        }
                    ],
                    "PrivateDnsName": "ip-172-31-22-237.ap-southeast-1.compute.internal",
                    "Attachment": {
                        "Status": "attaching",
                        "DeviceIndex": 0,
                        "DeleteOnTermination": true,
                        "AttachmentId": "eni-attach-dd8a93f4",
                        "AttachTime": "2014-03-19T15:38:54.000Z"
                    },
                    "Groups": [
                        {
                            "GroupName": "MySecurityGroup",
                            "GroupId": "sg-c66383a9"
                        }
                    ],
                    "SubnetId": "subnet-da3f8ab2",
                    "OwnerId": "174078020804",
                    "PrivateIpAddress": "172.31.22.237"
                }
            ],
            "SourceDestCheck": true,
            "Placement": {
                "Tenancy": "default",
                "GroupName": null,
                "AvailabilityZone": "ap-southeast-1b"
            },
            "Hypervisor": "xen",
            "BlockDeviceMappings": [],
            "Architecture": "x86_64",
            "StateReason": {
                "Message": "pending",
                "Code": "pending"
            },
            "RootDeviceName": "/dev/sda1",
            "VirtualizationType": "paravirtual",
            "RootDeviceType": "ebs",
            "AmiLaunchIndex": 0
        }
    ]
}

指定機器的名稱

aws ec2 create-tags --resources "i-d4ce29fc" --tags "Key=Name,Value=MyServer"
{
    "return": "true"
}

停止機器

aws ec2 stop-instances --instance-ids i-3c175414
{
    "StoppingInstances": [
        {
            "InstanceId": "i-3c175414",
            "CurrentState": {
                "Code": 64,
                "Name": "stopping"
            },
            "PreviousState": {
                "Code": 16,
                "Name": "running"
            }
        }
    ]
}

刪除機器

aws ec2 terminate-instances --instance-ids i-3c175414
{
    "TerminatingInstances": [
        {
            "InstanceId": "i-3c175414",
            "CurrentState": {
                "Code": 48,
                "Name": "terminated"
            },
            "PreviousState": {
                "Code": 80,
                "Name": "stopped"
            }
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment