खोज…


टिप्पणियों

विवरण

AWS कमांड लाइन इंटरफ़ेस (CLI) आपकी AWS सेवाओं का प्रबंधन करने के लिए एक एकीकृत उपकरण है। डाउनलोड करने और कॉन्फ़िगर करने के लिए सिर्फ एक उपकरण के साथ, आप कमांड लाइन से कई AWS सेवाओं को नियंत्रित कर सकते हैं और उन्हें स्क्रिप्ट के माध्यम से स्वचालित कर सकते हैं।

AWS सीएलआई ने अमेजन एस 3 से और उसके लिए कुशल फाइल ट्रांसफर के लिए सरल फ़ाइल कमांड का एक नया सेट पेश किया है।

समर्थित सेवाएँ

उपलब्ध सेवाओं की सूची के लिए आप AWS कमांड लाइन इंटरफेस के साथ उपयोग कर सकते हैं, AWS CLI कमांड संदर्भ में उपलब्ध सेवाएँ देखें।

GWSHub पर AWS कमांड लाइन इंटरफ़ेस

आप https://github.com/aws/aws-cli प्रोजेक्ट में GitHub पर AWS CLI के लिए सोर्स कोड और देख सकते हैं।

संस्करण

संस्करण रिलीज़ की तारीख
1.10.38 2016/06/14
1.10.35 2016/06/03
1.10.33 2016/05/25
1.10.30 2016/05/18

स्थापना और सेटअप

आपकी मशीन पर AWS CLI को स्थापित करने के लिए कई अलग-अलग तरीके हैं, जो आपके द्वारा उपयोग किए जा रहे ऑपरेटिंग सिस्टम और पर्यावरण पर निर्भर करता है:

Microsoft Windows पर - MSI इंस्टॉलर का उपयोग करें। लिनक्स, ओएस एक्स या यूनिक्स पर - पाइप (पायथन सॉफ्टवेयर के लिए एक पैकेज प्रबंधक) का उपयोग करें या बंडल किए गए इंस्टॉलर के साथ मैन्युअल रूप से इंस्टॉल करें।

पाइप का उपयोग कर स्थापित करें:

आपको अजगर को स्थापित करने की आवश्यकता होगी (संस्करण 2, 2.6.5 +, 3 या 3.3+)। इससे जाँच करें

python --version

pip --help

यह देखते हुए कि ये दोनों स्थापित हैं, aws cli को स्थापित करने के लिए निम्न कमांड का उपयोग करें।

sudo pip install awscli

Windows पर स्थापित करें AWS CLI Microsoft Windows XP या बाद में समर्थित है। विंडोज उपयोगकर्ताओं के लिए, MSI इंस्टॉलेशन पैकेज किसी अन्य पूर्वापेक्षा को स्थापित किए बिना AWS CLI स्थापित करने के लिए एक परिचित और सुविधाजनक तरीका प्रदान करता है। विंडोज उपयोगकर्ताओं को एमएसआई इंस्टॉलर का उपयोग करना चाहिए जब तक कि वे पैकेज प्रबंधन के लिए पहले से ही पाइप का उपयोग नहीं कर रहे हों।

डाउनलोड किए गए MSI इंस्टॉलर को चलाएं। दिखाई देने वाले निर्देशों का पालन करें।

बंडल इंस्टॉलर का उपयोग करके एडब्ल्यूएस सीएलआई स्थापित करने के लिए

आवश्यक शर्तें:

  • लिनक्स, ओएस एक्स, या यूनिक्स
  • पायथन 2 संस्करण 2.6.5+ या पायथन 3 संस्करण 3.3+
  1. WWS या कर्ल का उपयोग करके AWS CLI बंडल किए गए इंस्टॉलर को डाउनलोड करें।

  2. पैकेज खोलना।

  3. स्थापित निष्पादन योग्य चलाएँ।

लिनक्स और ओएस एक्स पर, यहां तीन कमांड हैं जो प्रत्येक चरण के अनुरूप हैं:

$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

OSB पर HomeBrew का उपयोग करके इंस्टॉल करें:

ओएस एक्स के लिए एक और विकल्प

brew install awscli

AWS CLI स्थापना का परीक्षण करें

पुष्टि करें कि सीएलआई मदद फ़ाइल को देखकर सही तरीके से स्थापित है। एक टर्मिनल, शेल या कमांड प्रॉम्प्ट खोलें, aws सहायता दर्ज करें और Enter दबाएं:

$ aws help

एडब्ल्यूएस सीएलआई को कॉन्फ़िगर करना

एक बार जब आप स्थापना को पूरा कर लेते हैं, तो आपको इसे कॉन्फ़िगर करने की आवश्यकता होती है। आपको अपनी पहुंच कुंजी और गुप्त कुंजी की आवश्यकता होगी जो आपको अपने खाते को aws पर बनाते समय मिलती है। आप एक डिफ़ॉल्ट क्षेत्र का नाम और एक डिफ़ॉल्ट आउटपुट प्रकार (पाठ | तालिका | json) भी निर्दिष्ट कर सकते हैं।

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: ENTER

सीएलआई उपकरण को अद्यतन करना

अमेज़ॅन समय-समय पर एडब्ल्यूएस टूल के नए संस्करण जारी करता है। यदि उपकरण पायथन पिप टूल का उपयोग करके स्थापित किया गया था, तो निम्न कमांड अपडेट के लिए दूरस्थ रिपॉजिटरी की जांच करेगा, और इसे आपके स्थानीय सिस्टम पर लागू करेगा।

$ pip install awscli --upgrade

एक नया प्रोफ़ाइल बनाना

myprofile नाम के साथ एक नया क्रेडेंशियल प्रोफ़ाइल सेटअप करने के लिए:

$ aws configure --profile myprofile
AWS Access Key ID [None]: ACCESSKEY
AWS Secret Access Key [None]: SECRETKEY
Default region name [None]: REGIONNAME
Default output format [None]: text | table | json

AWS पहुंच कुंजी आईडी और गुप्त के लिए, AWS कंसोल में IAM उपयोगकर्ता बनाएं और इसके लिए कुंजियाँ बनाएँ।

क्षेत्र प्रारूप में आदेश के लिए डिफ़ॉल्ट क्षेत्र हो जाएगा eu-west-1 या us-east-1

डिफ़ॉल्ट आउटपुट स्वरूप या तो text , table या json

अब आप अन्य नामों का उपयोग कर सकते हैं - अन्य विकल्प - --profile विकल्प का उपयोग करके, जैसे:

$ aws ec2 describe-instances --profile myprofile

अन्य भाषाओं के लिए AWS लाइब्रेरी (जैसे कि रूबी के लिए aws-sdk या पायथन के लिए boto3 ) के पास आपके द्वारा बनाई गई प्रोफ़ाइल का उपयोग करने के विकल्प भी हैं। उदाहरण के लिए boto3 में एक नया सत्र boto3 इस तरह से किया जा सकता है, boto3.Session(profile_name:'myprofile') और यह आपके द्वारा प्रोफाइल के लिए बनाई गई क्रेडेंशियल्स का उपयोग करेगा।

आपके aws-cli कॉन्फ़िगरेशन का विवरण ~/.aws/config और ~/.aws/credentials (linux और mac-os पर) में पाया जा सकता है। ये विवरण वहां से मैन्युअल रूप से संपादित किए जा सकते हैं।

Aws cli कमांड का उपयोग करना

Aws cli का उपयोग करने के लिए वाक्य रचना इस प्रकार है:

aws [options] <command> <subcommand> [parameters]

'Ec2' कमांड और 'डिस्क्रिप्शन-इंस्टैंस' सबकांड का उपयोग करने वाले कुछ उदाहरण:

aws ec2 describe-instances

aws ec2 describe-instances --instance-ids <your-id>

नकली आईडी के साथ उदाहरण:

aws ec2 describe-instances --instance-ids i-c71r246a

सूची S3 बाल्टी

aws s3 ls

एक नामांकित प्रोफ़ाइल का उपयोग करें

aws --profile myprofile s3 ls

सभी वस्तुओं को एक बाल्टी में सूचीबद्ध करें, जिसमें फ़ोल्डर्स शामिल हैं, मानव-पठनीय प्रारूप में आकार और अंत में बाल्टी के गुणों का सारांश -

aws s3 ls --recursive --summarize --human-readable s3://<bucket_name>/

बश के साथ उबंटू के लिए AWS संकलनकर्ता

निम्नलिखित उपयोगिता का उपयोग ऑटो-कमांड के पूरा होने के लिए किया जा सकता है:

$ which aws_completer
/usr/bin/aws_completer

$ complete -C '/usr/bin/aws_completer' aws

भविष्य के शेल सत्रों के लिए, इसे अपने ~ / .bashrc पर जोड़ें

$ echo "complete -C '/usr/bin/aws_completer' aws" >> ~/.bashrc

जाँच करने के लिए, टाइप करें:

$ aws ec

[TAB] कुंजी दबाएं, इसमें स्वचालित रूप से 2 जोड़ना चाहिए:

$ aws ec2

AWS सीएलआई धोखा शीट - सभी सीएलआई आदेशों की सूची

सेट अप

AWS CLI स्थापित करें

AWS सीएलआई AWS संसाधनों के प्रबंधन के लिए एक आम सीएलआई उपकरण है। इस एकल टूल से हम सभी अर्स संसाधनों का प्रबंधन कर सकते हैं

sudo apt-get install -y python-dev python-pip
sudo pip install awscli
aws --version
aws configure

बैश वन-लाइनर्स

cat <file> # output a file
tee # split output into a file
cut -f 2 # print the 2nd column, per line
sed -n '5{p;q}' # print the 5th line in a file
sed 1d # print all lines, except the first
tail -n +2 # print all lines, starting on the 2nd
head -n 5 # print the first 5 lines
tail -n 5 # print the last 5 lines

expand # convert tabs to 4 spaces
unexpand -a # convert 4 spaces to tabs
wc # word count
tr ' ' \\t # translate / convert characters to other characters

sort # sort data
uniq # show only unique entries
paste # combine rows of text, by line
join # combine rows of text, by initial column value




Cloudtrail - लॉगिंग और ऑडिटिंग

http://docs.aws.amazon.com/cli/latest/reference/cloudtrail/ 5 ट्रेल्स कुल, संसाधन स्तर की अनुमति के लिए समर्थन के साथ

# list all trails
aws cloudtrail describe-trails

# list all S3 buckets
aws s3 ls

# create a new trail
aws cloudtrail create-subscription \
    --name awslog \
    --s3-new-bucket awslog2016

# list the names of all trails
aws cloudtrail describe-trails --output text | cut -f 8

# get the status of a trail
aws cloudtrail get-trail-status \
    --name awslog

# delete a trail
aws cloudtrail delete-trail \
    --name awslog

# delete the S3 bucket of a trail
aws s3 rb s3://awslog2016 --force

# add tags to a trail, up to 10 tags
aws cloudtrail add-tags \
    --resource-id awslog \
    --tags-list "Key=log-type,Value=all"

# list the tags of a trail
aws cloudtrail list-tags \
    --resource-id-list 

# remove a tag from a trail
aws cloudtrail remove-tags \
    --resource-id awslog \
    --tags-list "Key=log-type,Value=all"




मैं हूँ

उपयोगकर्ता

https://blogs.aws.amazon.com/security/post/Tx15CIT22V4J8RP/How-to-rotate-access-keys-for-IAM-users http://docs.aws.bazon.com/IAM/latest/UserGuide /reference_iam-limits.html सीमाएँ = 5000 उपयोगकर्ता, 100 समूह, 250 भूमिकाएँ, 2 पहुंच कुंजियाँ / उपयोगकर्ता

http://docs.aws.amazon.com/cli/latest/reference/iam/index.html

# list all user's info
aws iam list-users

# list all user's usernames
aws iam list-users --output text | cut -f 6

# list current user's info
aws iam get-user

# list current user's access keys
aws iam list-access-keys

# crate new user
aws iam create-user \
    --user-name aws-admin2

# create multiple new users, from a file
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
    aws iam create-user \
        --user-name $userName
done

# list all users
aws iam list-users --no-paginate

# get a specific user's info
aws iam get-user \
    --user-name aws-admin2

# delete one user
aws iam delete-user \
    --user-name aws-admin2

# delete all users
# allUsers=$(aws iam list-users --output text | cut -f 6);
allUsers=$(cat ./user-names.txt)
for userName in $allUsers; do
    aws iam delete-user \
        --user-name $userName
done

पासवर्ड नीति

http://docs.aws.amazon.com/cli/latest/reference/iam/

# list policy
# http://docs.aws.amazon.com/cli/latest/reference/iam/get-account-password-policy.html
aws iam get-account-password-policy

# set policy
# http://docs.aws.amazon.com/cli/latest/reference/iam/update-account-password-policy.html
aws iam update-account-password-policy \
    --minimum-password-length 12 \
    --require-symbols \
    --require-numbers \
    --require-uppercase-characters \
    --require-lowercase-characters \
    --allow-users-to-change-password

# delete policy
# http://docs.aws.amazon.com/cli/latest/reference/iam/delete-account-password-policy.html
aws iam delete-account-password-policy

पहुंच कुंजी

http://docs.aws.amazon.com/cli/latest/reference/iam/

# list all access keys
aws iam list-access-keys

# list access keys of a specific user
aws iam list-access-keys \
    --user-name aws-admin2

# create a new access key
aws iam create-access-key \
    --user-name aws-admin2 \
    --output text | tee aws-admin2.txt

# list last access time of an access key
aws iam get-access-key-last-used \
    --access-key-id AKIAINA6AJZY4EXAMPLE

# deactivate an acccss key
aws iam update-access-key \
    --access-key-id AKIAI44QH8DHBEXAMPLE \
    --status Inactive \
    --user-name aws-admin2

# delete an access key
aws iam delete-access-key \
    --access-key-id AKIAI44QH8DHBEXAMPLE \
    --user-name aws-admin2

समूह, नीतियां, प्रबंधित नीतियां

http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html http://docs.aws.amazon.com/cli/latest/reference/iam/

# list all groups
aws iam list-groups

# create a group
aws iam create-group --group-name FullAdmins

# delete a group
aws iam delete-group \
    --group-name FullAdmins

# list all policies
aws iam list-policies

# get a specific policy
aws iam get-policy \
    --policy-arn <value>

# list all users, groups, and roles, for a given policy
aws iam list-entities-for-policy \
    --policy-arn <value>

# list policies, for a given group
aws iam list-attached-group-policies \
    --group-name FullAdmins

# add a policy to a group
aws iam attach-group-policy \
    --group-name FullAdmins \
    --policy-arn arn:aws:iam::aws:policy/AdministratorAccess

# add a user to a group
aws iam add-user-to-group \
    --group-name FullAdmins \
    --user-name aws-admin2

# list users, for a given group
aws iam get-group \
    --group-name FullAdmins

# list groups, for a given user
aws iam list-groups-for-user \
    --user-name aws-admin2

# remove a user from a group
aws iam remove-user-from-group \
    --group-name FullAdmins \
    --user-name aws-admin2

# remove a policy from a group
aws iam detach-group-policy \
    --group-name FullAdmins \
    --policy-arn arn:aws:iam::aws:policy/AdministratorAccess

# delete a group
aws iam delete-group \
    --group-name FullAdmins




EC2

keypairs

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html

# list all keypairs
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-key-pairs.html
aws ec2 describe-key-pairs

# create a keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/create-key-pair.html
aws ec2 create-key-pair \
    --key-name <value>

# create a new private / public keypair, using RSA 2048-bit
ssh-keygen -t rsa -b 2048

# import an existing keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/import-key-pair.html
aws ec2 import-key-pair \
    --key-name keyname_test \
    --public-key-material file:///home/apollo/id_rsa.pub

# delete a keypair
# http://docs.aws.amazon.com/cli/latest/reference/ec2/delete-key-pair.html
aws ec2 delete-key-pair \
    --key-name <value>

सुरक्षा समूह

http://docs.aws.amazon.com/cli/latest/reference/ec2/index.html

# list all security groups
aws ec2 describe-security-groups

# create a security group
aws ec2 create-security-group \
    --vpc-id vpc-1a2b3c4d \
    --group-name web-access \
    --description "web access"

# list details about a securty group
aws ec2 describe-security-groups \
    --group-id sg-0000000

# open port 80, for everyone
aws ec2 authorize-security-group-ingress \
    --group-id sg-0000000 \
    --protocol tcp \
    --port 80 \
    --cidr 0.0.0.0/24

# get my public ip
my_ip=$(dig +short myip.opendns.com @resolver1.opendns.com);
echo $my_ip

# open port 22, just for my ip
aws ec2 authorize-security-group-ingress \
    --group-id sg-0000000 \
    --protocol tcp \
    --port 80 \
    --cidr $my_ip/24

# remove a firewall rule from a group
aws ec2 revoke-security-group-ingress \
    --group-id sg-0000000 \
    --protocol tcp \
    --port 80 \
    --cidr 0.0.0.0/24

# delete a security group
aws ec2 delete-security-group \
    --group-id sg-00000000

उदाहरण

http://docs.aws.amazon.com/cli/latest/reference/ec2/index.html

# list all instances (running, and not running)
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html
aws ec2 describe-instances

# create a new instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html
aws ec2 run-instances \
    --image-id ami-f0e7d19a \    
    --instance-type t2.micro \
    --security-group-ids sg-00000000 \
    --dry-run

# stop an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/terminate-instances.html
aws ec2 terminate-instances \
    --instance-ids <instance_id>

# list status of all instances
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instance-status.html
aws ec2 describe-instance-status

# list status of a specific instance
aws ec2 describe-instance-status \
    --instance-ids <instance_id>

टैग

# list the tags of an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-tags.html
aws ec2 describe-tags

# add a tag to an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/create-tags.html
aws ec2 create-tags \
    --resources "ami-1a2b3c4d" \
    --tags Key=name,Value=debian

# delete a tag on an instance
# http://docs.aws.amazon.com/cli/latest/reference/ec2/delete-tags.html
aws ec2 delete-tags \
    --resources "ami-1a2b3c4d" \
    --tags Key=Name,Value=




Cloudwatch

लॉग समूह

http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/WhatIsCloudWatchLogs.html http://docs.aws.amazon.com/cli/latest-reference/logs/index.html#cli-aws-logs

एक समूह बनाएं

http://docs.aws.amazon.com/cli/latest/reference/logs/create-log-group.html

aws logs create-log-group \
    --log-group-name "DefaultGroup"
सभी लॉग समूहों को सूचीबद्ध करें

http://docs.aws.amazon.com/cli/latest/reference/logs/describe-log-groups.html

aws logs describe-log-groups

aws logs describe-log-groups \
    --log-group-name-prefix "Default"
एक समूह हटाएँ

http://docs.aws.amazon.com/cli/latest/reference/logs/delete-log-group.html

aws logs delete-log-group \
    --log-group-name "DefaultGroup"

लॉग स्ट्रीम

# Log group names can be between 1 and 512 characters long. Allowed
# characters include a-z, A-Z, 0-9, '_' (underscore), '-' (hyphen),
# '/' (forward slash), and '.' (period).

# create a log stream
# http://docs.aws.amazon.com/cli/latest/reference/logs/create-log-stream.html
aws logs create-log-stream \
    --log-group-name "DefaultGroup" \
    --log-stream-name "syslog"

# list details on a log stream
# http://docs.aws.amazon.com/cli/latest/reference/logs/describe-log-streams.html
aws logs describe-log-streams \
    --log-group-name "syslog"

aws logs describe-log-streams \
    --log-stream-name-prefix "syslog"

# delete a log stream
# http://docs.aws.amazon.com/cli/latest/reference/logs/delete-log-stream.html
aws logs delete-log-stream \
    --log-group-name "DefaultGroup" \
    --log-stream-name "Default Stream"


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow