• 2026 年 4 月 30 日之後將不再提供 AWS Systems Manager CloudWatch Dashboard。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板,就像現在一樣。如需詳細資訊,請參閱 Amazon CloudWatch Dashboard 文件。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Amazon Q 建立即時節點存取的核准政策
在命令列中使用 Amazon Q Developer,可在軟體開發的各個層面提供指導和支援。對於即時節點存取,Amazon Q 可產生和更新政策的程式碼、分析政策陳述式等,協助您建立核准政策。以下資訊說明如何使用適用於命令列的 Amazon Q 來建立核准政策。
識別您的使用案例
建立核准政策的第一步是清楚定義您的使用案例。例如,在您的組織中,您可能想要自動核准對具有 Environment:Testing 標籤之節點的存取請求。您可能也想要明確拒絕自動核准以 TEMP 開頭的員工 ID 對具有 Environment:Production 標籤之節點的存取請求。對於具有 Tier:Database 標籤的節點,您可能想要設定兩個層級的手動核准。
在任何特定案例中,您可能會偏好某個政策或條件。因此,建議您明確定義政策行為,以便決定哪些陳述式最適合您的使用案例,同時還要明確定義偏好設定。
設定開發環境
在要開發核准政策的位置安裝適用於命令列的 Amazon Q。如需有關安裝適用於命令列的 Amazon Q 的資訊,請參閱 Amazon Q Developer User Guide 中的 Installing Amazon Q for command line。
我們也建議您為 AWS 文件安裝 MCP 伺服器。此 MCP 伺服器會將適用於命令列的 Amazon Q 連線至最新的文件資源。如需有關將 MCP 與適用於命令列的 Amazon Q 搭配使用的資訊,請參閱 Amazon Q Developer User Guide 中的 Using MCP with Amazon Q Developer。
如需 AWS 文件 MCP 伺服器的詳細資訊,請參閱 AWS 文件 MCP 伺服器
如果您尚未安裝和設定 AWS CLI。有關資訊,請參閱 Installing or updating the latest version of the AWS CLI。
開發核准政策內容
識別使用案例並設定環境後,即可準備開發政策適用的內容。您的使用案例和偏好設定將主要決定您使用的核准政策和陳述式類型。
如果您不確定如何使用特定政策,或需要有關政策結構描述的詳細資訊,請參閱為您的節點建立核准政策和後續主題。這些主題詳細說明如何評估政策,並提供有效的範例陳述式。
下列程序說明如何使用適用於命令列的 Amazon Q 建立核准政策。
注意
Amazon Q Developer 使用生成式 AI。您可能需要驗證回應內容。請參閱AWS
負責任的 AI 政策
使用適用於命令列的 Amazon Q 建立核准政策
-
開啟終端並使用 Amazon Q 啟動工作階段。
$ q chat
-
輸入提示並描述您要建立的政策陳述式類型。例如,如果使用先前的核准政策案例,您可以輸入下列提示:
Create a Cedar policy statement that allows a principal to use the “getTokenForInstanceAccess" action for a resource that has a tag key “Environment” and tag value of “Testing”. Use the following example statement for reference to verify the syntax. permit ( principal in AWS::IdentityStore::Group::"e8c17310-e011-7089-d989-10da1EXAMPLE", action == AWS::SSM::Action::"getTokenForInstanceAccess", resource ) when { principal has organization && resource.hasTag("Engineering") && resource.hasTag("Production") && principal.organization == "Platform" }; The Cedar policy statement you create must be valid. Validate the Cedar statement using the AWS documentation provided for just-in-time node access policy statement structure and make sure you abide by the schema. -
輸入此範例提示會產生下列輸出:
Based on the AWS documentation for Cedar policy statements and the examples provided, I'll create a valid Cedar policy statement that allows a principal to use the "getTokenForInstanceAccess" action for resources with the tag key "Environment" and tag value "Testing". Here's the Cedar policy statement: permit ( principal, action == AWS::SSM::Action::"getTokenForInstanceAccess", resource ) when { resource.hasTag("Environment") && resource.getTag("Environment") == "Testing" }; This policy statement: 1. Uses the permit effect to allow access 2. Applies to any principal (since no specific principal is defined) 3. Specifically targets the "getTokenForInstanceAccess" action 4. Applies to resources that have a tag with key "Environment" and value "Testing" 5. Uses the proper syntax for the condition clause with the hasTag() and getTag() operators The statement follows the Cedar policy language structure as documented in the AWS Systems Manager documentation for just-in-time node access policies. -
將政策陳述式貼到新的 Cedar 檔案中,以驗證語法。您也可以使用 Cedar 演練場
驗證陳述式。 -
驗證陳述式之後,儲存 Cedar 檔案。
-
從終端機執行下列 AWS CLI 命令,以使用您的政策內容建立 SSM 文件。在生產環境中使用核准政策之前,請使用 AWS 帳戶 和 中的身分和節點子集來測試核准政策 AWS 區域。
注意
對於自動核准政策,文件名稱必須為
SSM-JustInTimeAccessAutoApprovalPolicy。每個 AWS 帳戶 和 只能有一個自動核准政策 AWS 區域。對於拒絕存取政策,文件名稱必須是SSM-JustInTimeAccessDenyAccessOrgPolicy。每個 AWS Organizations 組織只能有一個拒絕存取政策,且必須在 Systems Manager 的委派管理員帳戶中建立政策。手動核准政策的命名限制與其他 SSM 文件相同。如需詳細資訊,請參閱 CreateDocument。