

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS SAM 先決條件
<a name="prerequisites"></a>

在安裝和使用 AWS Serverless Application Model 命令列界面 () 之前，請先完成下列先決條件AWS SAM CLI。

若要使用 AWS SAM CLI，您需要下列項目：
+  AWS 帳戶、 AWS Identity and Access Management (IAM) 登入資料和 IAM 存取金鑰對。
+ 用來設定 AWS 登入資料的 AWS Command Line Interface (AWS CLI)。

**Topics**
+ [

## 步驟 1：註冊 AWS 帳戶
](#prerequisites-sign-up)
+ [

## 步驟 2：建立 IAM 使用者帳戶
](#prerequisites-create-user)
+ [

## 步驟 3：建立存取金鑰 ID 和私密存取金鑰
](#prerequisites-create-keys)
+ [

## 步驟 4：安裝 AWS CLI
](#prerequisites-install-cli)
+ [

## 步驟 5：使用 AWS CLI 設定 AWS 登入資料
](#prerequisites-configure-credentials)
+ [

## 步驟 6：（選用） 安裝 AWS Toolkit for VS 程式碼
](#prerequisites-install-vscode)
+ [

## 後續步驟
](#prerequisites-next-steps)

## 步驟 1：註冊 AWS 帳戶
<a name="prerequisites-sign-up"></a>

如果您沒有 AWS 帳戶，請完成下列步驟來建立一個。

**註冊 AWS 帳戶**

1. 開啟 [https://portal.aws.amazon.com/billing/signup](https://portal.aws.amazon.com/billing/signup)。

1. 請遵循線上指示進行。

   部分註冊程序需接收來電或簡訊，並在電話鍵盤輸入驗證碼。

   當您註冊 時 AWS 帳戶，*AWS 帳戶根使用者*會建立 。根使用者有權存取該帳戶中的所有 AWS 服務 和資源。作為安全最佳實務，請將管理存取權指派給使用者，並且僅使用根使用者來執行[需要根使用者存取權的任務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html#root-user-tasks)。

## 步驟 2：建立 IAM 使用者帳戶
<a name="prerequisites-create-user"></a>

若要建立管理員使用者，請選擇下列其中一個選項。


****  

| 選擇一種管理管理員的方式 | 到 | 根據 | 您也可以 | 
| --- | --- | --- | --- | 
| 在 IAM Identity Center (建議) | 使用短期憑證存取 AWS。這與安全性最佳實務一致。有關最佳實務的資訊，請參閱 *IAM 使用者指南*中的 [IAM 安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#bp-users-federation-idp)。 | 請遵循 AWS IAM Identity Center 使用者指南的[入門](https://docs.aws.amazon.com//singlesignon/latest/userguide/getting-started.html)中的說明。 | 在 AWS Command Line Interface 使用者指南中設定 [AWS CLI 以使用 來設定 AWS IAM Identity Center](https://docs.aws.amazon.com//cli/latest/userguide/cli-configure-sso.html)程式設計存取。 | 
| 在 IAM 中 (不建議使用) | 使用長期憑證存取 AWS。 | 請遵循《IAM 使用者指南》中[建立 IAM 使用者以進行緊急存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started-emergency-iam-user.html) 的指示。 | 請依照《IAM 使用者指南》中的[管理 IAM 使用者的存取金鑰](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_credentials_access-keys.html)設定以程式設計方式存取。 | 

## 步驟 3：建立存取金鑰 ID 和私密存取金鑰
<a name="prerequisites-create-keys"></a>

對於 CLI 存取，您需要存取金鑰 ID 和私密存取金鑰。盡可能使用臨時憑證，而不是長期存取金鑰。臨時憑證包含存取金鑰 ID、私密存取金鑰，以及指出憑證何時到期的安全符記。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[將臨時登入資料與 AWS 資源](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)搭配使用。

如果使用者想要與 AWS 外部互動，則需要程式設計存取 AWS 管理主控台。授予程式設計存取權的方式取決於正在存取的使用者類型 AWS。

若要授予使用者程式設計存取權，請選擇下列其中一個選項。


****  

| 哪個使用者需要程式設計存取權？ | 到 | 根據 | 
| --- | --- | --- | 
| IAM | （建議） 使用主控台登入資料做為臨時登入資料，以簽署對 AWS CLI、 AWS SDKs程式設計請求。 AWS APIs |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/prerequisites.html)  | 
|  人力資源身分 (IAM Identity Center 中管理的使用者)  | 使用暫時登入資料簽署對 AWS CLI、 AWS SDKs程式設計請求。 AWS APIs |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/prerequisites.html)  | 
| IAM | 使用暫時登入資料簽署對 AWS CLI、 AWS SDKs程式設計請求。 AWS APIs | 遵循《IAM 使用者指南》中[將臨時登入資料與 AWS 資源](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)搭配使用的指示。 | 
| IAM | (不建議使用)使用長期憑證簽署對 AWS CLI、 AWS SDKs程式設計請求。 AWS APIs |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/serverless-application-model/latest/developerguide/prerequisites.html)  | 

## 步驟 4：安裝 AWS CLI
<a name="prerequisites-install-cli"></a>

是一種 AWS CLI 開放原始碼工具，可讓您 AWS 服務 在命令列 Shell 中使用命令與 互動。對於 AWS SAM CLI設定登入資料等活動 AWS CLI ， 需要 。若要進一步了解 AWS CLI，請參閱*AWS Command Line Interface 《 使用者指南*》中的[什麼是 AWS Command Line Interface？](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)。

若要安裝 AWS CLI，請參閱*AWS Command Line Interface 《 使用者指南*》中的[安裝或更新最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

## 步驟 5：使用 AWS CLI 設定 AWS 登入資料
<a name="prerequisites-configure-credentials"></a>

**使用 IAM Identity Center 設定登入資料**
+ 若要使用 IAM Identity Center 設定登入資料，請參閱[使用設定 sso 精靈 AWS 設定您的設定檔](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html#cli-configure-sso-configure)。

**使用 設定登入資料 AWS CLI**

1. 從`aws configure`命令列執行 命令。

1. 設定下列項目。選取每個連結以進一步了解：

   1. [ 存取金鑰 ID](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds)

   1. [ 私密存取金鑰](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds)

   1. [AWS 區域](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-region)

   1. [ 輸出格式](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-format)

   下列範例顯示範本值。

   ```
   $ 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]: json
   ```

會將此資訊 AWS CLI 儲存在 `credentials`和 `config`檔案中名為 的*設定檔* （設定集合） `default`中。這些檔案位於主目錄中的 `.aws` 檔案中。根據預設，當您執行未明確指定要使用之設定檔的 AWS CLI 命令時，會使用此設定檔中的資訊。如需 `credentials` 檔案的詳細資訊，請參閱*AWS Command Line Interface 《 使用者指南*》中的[組態和登入資料檔案設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)。

如需設定登入資料的詳細資訊，例如使用現有的組態和登入資料檔案，請參閱*AWS Command Line Interface 《 使用者指南*》中的[快速設定](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html)。

## 步驟 6：（選用） 安裝 AWS Toolkit for VS 程式碼
<a name="prerequisites-install-vscode"></a>

對於偏好整合式開發環境的開發人員， AWS Toolkit for VS Code 為無伺服器開發提供了強大的功能，包括視覺化偵錯、CodeLens 整合和簡化的部署工作流程。

**VS 程式碼開發的先決條件**
+ 安裝在系統上的 Visual Studio Code (1.73.0 版或更新版本）
+ VS 程式碼的 YAML 語言支援延伸

**安裝 AWS Toolkit for VS 程式碼**

1. 開啟 Visual Studio 程式碼

1. 開啟延伸模組檢視 (Ctrl\$1Shift\$1X 或 Cmd\$1Shift\$1X)

1. 搜尋「AWS Toolkit」

1. Amazon Web Services 安裝「AWS Toolkit」延伸模組

1. Red Hat 安裝「YAML」延伸模組 (SAM 範本 CodeLens 功能需要）

**搭配 SAM 使用 VS AWS 程式碼的優點**
+ 視覺化偵錯：在本機設定中斷點並逐步完成 Lambda 函數
+ CodeLens 整合：直接從 SAM 範本建置、部署和叫用函數
+ 整合式終端機：存取 AWS SAM AWS CLI 命令而不離開編輯器
+ 範本驗證：即時驗證和 IntelliSense for SAM 範本

如需有關在 VS Code 中設定 AWS 登入資料的資訊，請參閱 AWS Toolkit for VS Code 使用者指南中的[設定登入資料](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-credentials.html)。

## 後續步驟
<a name="prerequisites-next-steps"></a>
+ 您現在可以安裝 AWS SAM CLI並開始使用 AWS SAM。若要安裝 AWS SAM CLI，請參閱 [安裝 AWS SAM CLI](install-sam-cli.md)。
+ 若要設定 Visual Studio Code 進行無伺服器開發，請參閱[設定 AWS Toolkit for VS Code](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setting-up.html)。