配置 aws cli_AWS CLI教程–如何安裝,配置和使用AWS CLI了解您的資源環境

配置 aws cli

How to get exactly the account and environment information you need to manage your AWS account using just the AWS CLI

如何僅使用AWS CLI準確獲取管理AWS賬戶所需的賬戶和環境信息

Installing the AWS CLI is actually quite simple. The best way to get it done is to head over to the AWS installation guide and follow instructions for your OS.

實際上,安裝AWS CLI非常簡單。 最好的方法是轉到AWS安裝指南并按照您的操作系統的說明進行操作。

Right now they're pushing us towards version 2 of the CLI and I haven't seen any reason not to go along. I'm working with Linux so that's where I'd head next.

目前,他們正在將我們推向CLI的第二版,而且我還沒有任何不接受的理由。 我正在使用Linux,所以接下來是我要去的地方。

To get it done, I'll paste the curl command from the Amazon page into my Linux shell that'll download the package and write it to a local zip file, which I'll then unzip. That'll create a new directory called aws that'll contain a install script, which I can run using sudo to get admin privileges. I'll run aws --version to confirm everything worked as it was supposed to.

為此,我將從Amazon頁面粘貼curl命令到Linux外殼程序中,該外殼程序將下載該程序包并將其寫入本地zip文件,然后將其解壓縮。 這將創建一個名為aws的新目錄,其中將包含一個安裝腳本,我可以使用sudo運行該腳本以獲取管理員權限。 我將運行aws --version來確認一切均按預期進行。

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
ls aws
sudo ./aws/install
aws --version

The next step will require one quick trip to the management console. You see, to authenticate the CLI to your account you'll need a valid access key. Now, the CLI has a "create-access-key" command that'll generate a new key, but that's only possible once I've authenticated. I'm sure you understand the problem with that.

下一步將需要快速訪問管理控制臺。 您會看到,要通過CLI對您的帳戶進行身份驗證,您將需要一個有效的訪問密鑰。 現在,CLI具有一個“ create-access-key”命令,該命令將生成一個新密鑰,但是只有在我通過身份驗證后才可能。 我敢肯定,您了解問題所在。

You access the security credentials page from the drop-down account menu at the top of any page on the console. With your credentials in hand, you can run "aws configure." You'll be prompted to enter your access key ID and the secret key itself. If you like you can then choose a default AWS region and output format. The format won't be an issue so I'll leave it as default.

您可以從控制臺任何頁面頂部的下拉帳戶菜單訪問安全憑證頁面。 有了憑據,您就可以運行“ aws configure”。 系統將提示您輸入訪問密鑰ID和密鑰本身。 如果愿意,可以選擇默認的AWS區域和輸出格式。 格式不會成為問題,因此我將其保留為默認格式。

aws configure

That's it. Just to confirm it all worked, I'll list all the S3 buckets in my account. With that, we'll all set to get down to work in the next clip.

而已。 為了確認一切正常,我將在帳戶中列出所有S3存儲桶。 這樣,我們所有人都將開始在下一個剪輯中工作。

aws s3 ls

You may already know that Amazon's CloudFormation service exists to let you manage your application infrastructure by organising it into stacks of your AWS account resources.

您可能已經知道Amazon的CloudFormation服務已經存在,可以通過將其組織到AWS賬戶資源的堆棧中來管理應用程序基礎架構。

The CloudFormation templates that define those stacks can be shared, edited, and launched anywhere, giving you predictable and reliable cloud application environments wherever and whenever you need them.

定義這些堆棧的CloudFormation模板可以在任何地方共享,編輯和啟動,從而在需要它們的地方隨時隨地為您提供可預測和可靠的云應用程序環境。

You may also know that you can mange your CloudFormation stacks both through the AWS Management Console and, as I discuss in my new Pluralsight course, Create and Manage Stacks with AWS CloudFormation Using the Command Line Interface, using the AWS CLI.

您可能還知道,您既可以通過AWS管理控制臺管理CloudFormation堆棧,也可以像我在新的Pluralsight課程中討論的那樣,使用AWS CLI 使用命令行界面通過AWS CloudFormation創建和管理堆棧 。

If you do choose to go with the AWS CLI – something I highly recommend – you'll need a way to gather key information about other account resources. But how you're expected to get that information through the CLI might, at first, not appear so obvious.

如果您確實選擇使用AWS CLI(我強烈建議您這樣做),則需要一種方法來收集有關其他賬戶資源的關鍵信息。 但是,起初,您期望如何通過CLI獲取該信息似乎不太明顯。

To show you what I mean, let's experiment with a more complex stack using a template that comes from the AWS documentation samples.

為了說明您的意思,讓我們使用來自AWS文檔樣本的模板嘗試更復雜的堆棧。

The Application Frameworks template set includes a template for auto scaled Linux servers that will come pre-provisioned with the Apache web server and the PHP scripting language, and a connection to a Multi-AZ RDS database instance running the MySQL database engine.

Application Frameworks模板集包括一個用于自動擴展Linux服務器的模板,該模板將隨Apache Web服務器和PHP腳本語言預先配置,并連接到運行MySQL數據庫引擎的Multi-AZ RDS數據庫實例。

You can click View from that AWS documentation page and take a look at the template itself. There you'll see Parameters sections defining the VPC and subnets into which your instance will launch and the MySQL database name, user, and password.

您可以從該AWS文檔頁面單擊查看,然后查看模板本身。 在這里,您會看到“參數”部分,這些部分定義了實例將啟動到的VP??C和子網以及MySQL數據庫名稱,用戶和密碼。

It's critical that all the right services know those details because, otherwise, they won't be able to talk to each other. We'll have to figure out a way to add those values. To get things going, you can simply click to view the template (which you can see here), and copy the contents, pasting it into a new JSON file on your local machine.

所有正確的服務都必須了解這些詳細信息,這很關鍵,因為否則它們將無法相互通信。 我們必須找出一種添加這些值的方法。 為了使事情順利進行,您只需單擊以查看模板( 可以在此處看到 ),然后復制內容,并將其粘貼到本地計算機上的新JSON文件中。

You use the CLI to fire up a Cloudformation stack using the create-stack command. The command, however, takes a few arguments to pass important information. This minimal example shows you how to point CloudFormation to your JSON template file, a name to assign to your stack, and a valid SSH key so I'll be able to log into the instance it creates.

您可以使用CLI使用create-stack命令啟動Cloudformation堆棧。 但是,該命令需要一些參數來傳遞重要信息。 這個最小的示例向您展示如何將CloudFormation指向您的JSON模板文件,一個要分配給您的堆棧的名稱以及一個有效的SSH密鑰,這樣我就可以登錄到它創建的實例。

aws cloudformation create-stack \--template-body file://lamp-as.json \--stack-name lamp \--parameters \ParameterKey=KeyName,ParameterValue=mykey

The problem is that, if you were to run that command against the template in your JSON document, it would fail. That's because, as you'll no doubt remember from looking through the template, there are some extra parameters that need satisfying. Specifically, we'll need references to a VPC and to two subnets - and because this is a multi-availability-zone deployment, they'll need to be in different zones.

問題是,如果要對JSON文檔中的模板運行該命令,它將失敗。 這是因為,毫無疑問,從瀏覽模板的過程中,您還需要了解一些額外的參數。 具體來說,我們需要引用一個VPC和兩個子網-由于這是一個多可用性區域部署,因此它們需要位于不同的區域中。

How will that work? It's the AWS CLI to the rescue. Need a VPC ID? Keeping in mind that VPCs are EC2 objects, you can run aws ec2 describe-vpcs and all the data you'll need - including the VPC ID - will magically appear. And subnets? Well more of the same, obviously. Just copy subnet IDs for any two of the subnets that will appear and you're in business.

那將如何工作? 這是要解救的AWS CLI。 需要一個VPC ID? 請記住,VPC是EC2對象,可以運行aws ec2 describe-vpcs,所有需要的數據-包括VPC ID-都會神奇地出現。 和子網? 顯然,更多的相同。 只需復制將出現的任何兩個子網的子網ID,即可開展業務。

aws ec2 describe-vpcs
aws ec2 describe-subnets

Now let's put all that information together into our new version of the create-stack command. You'll need to be careful with this as there are some nasty gotchas in the syntax.

現在,讓我們將所有這些信息放到新版本的create-stack命令中。 您需要注意這一點,因為語法中有些討厭的地方。

aws cloudformation create-stack \--template-body file://lamp-as.json \--stack-name lamp-as \--parameters \ParameterKey=KeyName,ParameterValue=mykey \ParameterKey=VpcId,ParameterValue=vpc-1ffbc964 \ParameterKey=Subnets,ParameterValue=\'subnet-0e170b31,subnet-52d6117c\' \ParameterKey=DBUser,ParameterValue=myadmin \ParameterKey=DBPassword,ParameterValue=mypass23

The first new parameter is VPC-ID. But make sure you get the case right: using an uppercase D in Id will cause the whole thing to fail. I don't know why they make things so difficult to live with, but that's what we've got.

第一個新參數是VPC-ID。 但是,請確保您理解的正確:在ID中使用大寫D會導致整個操作失敗。 我不知道為什么他們讓生活變得如此困難,但這就是我們所擁有的。

The next one is even more delicate. Since we need two subnets, we'll need to enter them on a single line separated by a comma - but no space. However, we'll also need to enclose the string within single apostrophes. But the CLI can't read apostrophes just like that, so we'll need to escape them using backslashes. Got that?

下一個更加精致。 由于我們需要兩個子網,因此需要在由逗號分隔的一行中輸入它們-但不能有空格。 但是,我們還需要將字符串括在單撇號內。 但是CLI不能像這樣讀取撇號,因此我們需要使用反斜杠對其進行轉義。 了解?

I'll also add those two database parameters: DBUser and my ultra secret, super cryptic DBPassword. Will it work? You betcha. But don't tell anyone how many times I had to try this without you watching before I got it right. Remember: failure is your friend.

我還將添加這兩個數據庫參數:DBUser和我的超級秘密,超級神秘的DBPassword。 能行嗎 完全正確。 但是,請不要告訴任何人在我理解正確之前我必須嘗試幾次卻沒有您的注意。 記住:失敗是你的朋友。

When our stack is good and launched (which could take as long as half an hour), running describe-stacks will give us our website URL.

當我們的堆棧良好并啟動時(可能需要半小時的時間),運行describe-stacks將為我們提供網站URL。

aws cloudformation describe-stacks

But that's not the whole story. ?I'm going to use another aws ec2 command - describe-instances this time - to get some information about the EC2 instances that were launched as part of this stack. This one will filter results, restricting output to only those instances that are currently running.

但這還不是全部。 我將使用另一個aws ec2命令-這次是describe-instances-獲取有關作為該堆棧的一部分啟動的EC2實例的一些信息。 這將過濾結果,將輸出限制為僅當前正在運行的那些實例。

aws ec2 describe-instances \--filters Name=instance-state-name,Values=running \--query 'Reservations[*].Instances[*].{Instance:InstanceId,PublicIPAddress:PublicIpAddress}'

I happen to have no other instances running in this region, so only the CloudFormation instances will show up. Now I use --query to further filter the output to give me only the Instance IDs and public IP addresses of those instances. There are, as you would expect, exactly two running.

我碰巧在該區域中沒有其他實例在運行,因此只會顯示CloudFormation實例。 現在,我使用--query進一步過濾輸出,以僅為我提供這些實例的實例ID和公共IP地址。 如您所料,有兩個正在運行。

Just a taste - and most of it related specifically to CloudFormation - but I think you get the idea of how information gathering works using the AWS CLI.

只是一種嘗試-大多數都與CloudFormation有關-但是我認為您已經了解了如何使用AWS CLI進行信息收集。

There's much more administration goodness in the form of books, courses, and articles available at my bootstrap-it.com.

我的bootstrap-it.com上提供了書籍,課程和文章形式的管理優勢。

翻譯自: https://www.freecodecamp.org/news/aws-cli-tutorial-install-configure-understand-resource-environment/

配置 aws cli

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390299.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390299.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390299.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

grep遞歸查找頭文件_Grep命令教程–如何使用遞歸查找在Linux和Unix中搜索文件

grep遞歸查找頭文件grep stands for Globally Search For Regular Expression and Print out. It is a command line tool used in UNIX and Linux systems to search a specified pattern in a file or group of files. grep代表全局搜索正則表達式并打印出來 。 它是UNIX和Li…

C++ 前置聲明

(一)class的前置聲明 class的前置聲明有兩種。 pre.hclass PreA {}; main.hclass PreA; class Main {};//或者 class Main {class PreA* A; }; (二) struct前置聲明 struct的前置聲明只能用第一種。 (三) 有typedef的前置聲明 Pr…

2.18 特殊權限set_uid 2.19 特殊權限set_gid 2.20 特殊權限stick_bit 2.21 軟鏈接文件 2.22 硬連接文件...

2019獨角獸企業重金招聘Python工程師標準>>> 特殊權限set_uid set_uid:該權限針對二進制可執行文件,使文件在執行階段具有文件所有者的權限; 通俗一點講就是,普通用戶想要訪問一個沒有其他用戶可執行權限的目錄時,暫時…

345. 反轉字符串中的元音字母

345. 反轉字符串中的元音字母 給你一個字符串 s ,僅反轉字符串中的所有元音字母,并返回結果字符串。 元音字母包括 ‘a’、‘e’、‘i’、‘o’、‘u’,且可能以大小寫兩種形式出現。 示例 1: 輸入:s “hello” 輸…

通過制作數字桌面游戲和Web應用程序學習JavaScript

Building 2D games can be a great way to learn JavaScript, especially when working through the basics of complex tabletop game logic.制作2D游戲可能是學習JavaScript的好方法,尤其是在研究復雜的桌面游戲邏輯基礎時。 In this series, I’m going to intr…

【HAVENT原創】Node Express API 通用配置

為什么80%的碼農都做不了架構師?>>> ( 基于 Express 4.x ) 啟動文件 /app.js: var express require(express); var bodyParser require(body-parser); var proxy require(http-proxy-middleware); var path require(path);var index re…

C#使用Json.NET解析Json

本文轉載自 http://xiaosheng.me/2016/10/01/article25/ 最近在 C# 項目中需要使用到 Json 格式的數據,我簡單上網搜索了一下,基本上有兩種操作 Json 數據的方法: 使用 Windows 系統自帶的類使用第三方的包本著“第三方包一定有比系統自帶類優…

現在JavaScript日期–如何在JavaScript中獲取當前日期

Many applications you build will have some sort of a date component, whether its the creation date of a resource, or the timestamp of an activity. 您構建的許多應用程序都將具有某種日期組件,無論是資源的創建日期還是活動的時間戳。 Dealing with date…

233. 數字 1 的個數

給定一個整數 n,計算所有小于等于 n 的非負整數中數字 1 出現的個數。 示例 1: 輸入:n 13 輸出:6 示例 2: 輸入:n 0 輸出:0 解題思路 正確性證明 例如:對于n3015&#xff0c…

Linux串口設置參數

為什么80%的碼農都做不了架構師?>>> 在Linux環境下,串口名從ttyS0開始依次是ttyS1、ttyS2等。在本程序中,使用ttyS0作為通信串口。在打開ttyS0的時候選項 O_NOCTTY 表示不能把本串口當成控制終端,否則用戶的鍵盤輸入信…

STM32F013 十元板

我大拇指般大小。STM32F103C8T6,64K Flash,20K RAM,m3的核。十元,應該是價格極限了吧。 通過USB供電(5V),也可以排針3.3V供電。可惜沒有引出5V排針。USB口可以供電和USB通訊,沒有USB…

如何在Python中建立和訓練K最近鄰和K-Means集群ML模型

One of machine learnings most popular applications is in solving classification problems.機器學習最流行的應用之一是解決分類問題。 Classification problems are situations where you have a data set, and you want to classify observations from that data set in…

552. 學生出勤記錄 II

552. 學生出勤記錄 II 可以用字符串表示一個學生的出勤記錄,其中的每個字符用來標記當天的出勤情況(缺勤、遲到、到場)。記錄中只含下面三種字符: ‘A’:Absent,缺勤 ‘L’:Late,遲…

C/C++中計算函數運行時間

#include<stdio.h> #include<time.h> clock_t start,stop;//clock_t 是clock&#xff08;&#xff09;函數返回變量的類型 double duration;//記錄被測函數的運行時間&#xff0c;以秒為單位 int main() { startclock();//開始計時 MyFunction();//把被測函數加在這…

作為一名前端開發工程師,你必須掌握的WEB模板引擎:Handlebars

為什么需要使用模板引擎&#xff1f; 關于為什么要使用模板引擎&#xff0c;按照我常說的一句話就是&#xff1a;不用重復造輪子了。 簡單來說&#xff0c;模板最本質的作用是“變靜為動”&#xff0c;一切利于這方面的都是優勢&#xff0c;不利于的都是劣勢。要想很好地實現“…

extjs 實用開發指南_如何提出有效問題:針對開發人員的實用指南

extjs 實用開發指南Learning is a journey that never ends. At every point in your career, you will keep learning, re-learning, and un-learning. 學習是一個永無止境的旅程。 在職業生涯的每個階段&#xff0c;您都會不斷學習&#xff0c;重新學習和不學習。 The abil…

LOJ 6270

最近&#xff08;一直&#xff09;有點&#xff08;很&#xff09;蠢 按照區間大小排序做區間包含多少區間的話 只用考慮 左端點比當前左端點小的和右端點比當前右端點大的&#xff0c;因為不可能同時滿足 關于K&#xff0c;就在做到K的時候減一下就好了&#xff0c;一直傻逼在…

Zabbix3.4安裝詳細步驟

Zabbix3.4安裝的詳細步驟一、zabbix介紹現在大多數公司都會用到監控軟件&#xff0c;主流的監控軟件就是Zabbix了&#xff0c;當然還會有Nagios等其他的軟件&#xff1a;zabbix是一個基于WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。zabbix能監視各種…

軟件自學成才到公司要學歷嗎_作為一名自學成才的移動開發人員,我在旅途中學到了什么

軟件自學成才到公司要學歷嗎In this post, Ill share my entire journey about how I became a professional mobile developer.在這篇文章中&#xff0c;我將分享我如何成為一名專業的移動開發人員的整個過程。 I hope that reading about my experience will help you refle…

cs231n---語義分割 物體定位 物體檢測 物體分割

1 語義分割 語義分割是對圖像中每個像素作分類&#xff0c;不區分物體&#xff0c;只關心像素。如下&#xff1a; &#xff08;1&#xff09;完全的卷積網絡架構 處理語義分割問題可以使用下面的模型&#xff1a; 其中我們經過多個卷積層處理&#xff0c;最終輸出體的維度是C*H…