本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Amazon Pinpoint 身分型政策範例
使用者和角色預設不具備建立或修改 Amazon Pinpoint 資源的許可。他們也無法使用 AWS Management Console AWS CLI、或執行工作 AWS API。IAM管理員必須建立IAM原則,授與使用者和角色權限,才能對所需的資源執行特定API作業。管理員接著必須將這些政策連接至需要這些許可的使用者或群組。
若要瞭解如何使用這些範例原則文件建立以IAM身分識別為基礎的JSON策略,請參閱使用IAM者指南中的JSON索引標籤上的建立策略。
主題
政策最佳實務
身分型政策會判斷您帳戶中的某個人員是否可以建立、存取或刪除 Amazon Pinpoint 資源。這些動作可能會讓您的 AWS 帳戶產生費用。當您建立或編輯身分型政策時,請遵循下列準則及建議事項:
-
開始使用 AWS 受管原則並邁向最低權限權限 — 若要開始授與使用者和工作負載的權限,請使用可授與許多常見使用案例權限的AWS 受管理原則。它們在您的 AWS 帳戶. 建議您透過定義特定於您使用案例的 AWS 客戶管理政策,進一步降低使用權限。如需詳細資訊,請參閱AWS 《IAM使用指南》中針對工作職能的AWS 受管理策略或受管理的策略。
-
套用最低權限權限 — 當您使用原則設定權限時,IAM只授與執行工作所需的權限。為實現此目的,您可以定義在特定條件下可以對特定資源採取的動作,這也稱為最低權限許可。如需有關使用套用權限IAM的詳細資訊,請參閱《使用指南》IAM中的IAM《策略與權限》。
-
使用IAM策略中的條件進一步限制存取 — 您可以在策略中新增條件,以限制對動作和資源的存取。例如,您可以撰寫政策條件,以指定必須使用傳送所有要求SSL。您也可以使用條件來授與對服務動作的存取權 (如透過特定) 使用這些動作 AWS 服務,例如 AWS CloudFormation。如需詳細資訊,請參閱《IAM使用指南》中的IAMJSON策略元素:條件。
-
使用 IAM Access Analyzer 驗證您的原IAM則,以確保安全和功能性的權限 — IAM Access Analyzer 會驗證新的和現有的原則,以便原則遵循IAM原則語言 (JSON) 和IAM最佳做法。IAMAccess Analyzer 提供超過 100 項原則檢查和可行的建議,協助您撰寫安全且功能正常的原則。如需詳細資訊,請參閱IAM使IAM用指南中的存取分析器原則驗證。
-
需要多因素驗證 (MFA) — 如果您的案例需要使IAM用者或 root 使用者 AWS 帳戶,請開啟以取得額外MFA的安全性。若要在呼叫API作業MFA時需要,請在原則中新增MFA條件。如需詳細資訊,請參閱《IAM使用指南》中的 < 設定MFA受保護的API存取 >。
如需有關中最佳作法的詳細資訊IAM,請參閱《IAM使用指南》IAM中的「安全性最佳作法」。
使用 Amazon Pinpoint 主控台
若要存取 Amazon Pinpoint 主控台,您必須擁有最基本的許可。這些許可必須允許您列出和檢視 AWS 帳戶中 Amazon Pinpoint 資源的詳細資訊。如果您建立的身分型政策,套用的許可比所需的最低權限更嚴格,那麼使用該政策的實體 (使用者或角色),其主控台將不能正常運作。若要確保這些實體可以使用 Amazon Pinpoint 主控台,請將政策連接到實體。如需詳細資訊,請參閱《使用指南》中的〈將權限新增至IAM使用者〉。
下列範例政策提供對特定 AWS 區域中 Amazon Pinpoint 主控台的唯讀存取權。其中包含 Amazon Pinpoint 主控台所依賴的其他服務的唯讀存取權,例如 Amazon 簡單電子郵件服務 (亞馬遜SES) 和 Amazon Kinesis。IAM
{ "Version": "2012-10-17", "Statement": [ { "Sid": "UseConsole", "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*" ], "Resource": "arn:aws:mobiletargeting:
region
:accountId
:*" }, { "Effect": "Allow", "Action": [ "firehose:ListDeliveryStreams", "iam:ListRoles", "kinesis:ListStreams", "s3:List*", "ses:Describe*", "ses:Get*", "ses:List*", "sns:ListTopics" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "accountId
" } } } ] }
在上述策略範例中,取代 region
用一個 AWS 區域的名稱,並替換 accountId
使用您的 AWS 帳戶 ID。
您不需要為只對 AWS CLI 或撥打電話的使用者允許最低主控台權限 AWS API。而是只允許存取符合他們嘗試執行之API作業的動作。
範例:存取單一 Amazon Pinpoint 專案
您也可以建立唯讀政策,只存取特定專案。以下範例政策可讓使用者登入主控台,並檢視專案清單。它也可讓使用者檢視 Amazon Pinpoint 主控台所依賴之其他 AWS 服務的相關資源相關資訊,例如亞馬遜SES和 Amazon Kinesis。IAM不過,此政策只讓使用者檢視政策中所指定之專案的相關資訊。您可以修改此原則,以允許存取其他專案或 AWS 區域。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewProject", "Effect": "Allow", "Action": "mobiletargeting:GetApps", "Resource": "arn:aws:mobiletargeting:
region
:accountId
:*" }, { "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*" ], "Resource": [ "arn:aws:mobiletargeting:region
:accountId
:apps/projectId
", "arn:aws:mobiletargeting:region
:accountId
:apps/projectId
/*", "arn:aws:mobiletargeting:region
:accountId
:reports" ] }, { "Effect": "Allow", "Action": [ "ses:Get*", "kinesis:ListStreams", "firehose:ListDeliveryStreams", "iam:ListRoles", "ses:List*", "sns:ListTopics", "ses:Describe*", "s3:List*" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "accountId
" } } } ] }
在前面的例子中,替換 region
以區 AWS 域的名稱取代 accountId
使用您的 AWS 帳戶 ID,並替換 projectId
使用您想要提供存取權的 Amazon Pinpoint 專案的 ID。
同樣地,您可以建立政策,授與 AWS 帳戶中的使用者,對其中一個 Amazon Pinpoint 專案進行有限寫入權限,例如具有專案 ID 的810c7aab86d42fb2b56c8c966example
專案。在此情況下,您希望允許使用者檢視、新增和更新專案元件 (例如區段和促銷活動),但不能刪除任何元件。
除了授與 mobiletargeting:Get
和 mobiletargeting:List
動作的許可之外,也請建立授與下列動作許可的政策:mobiletargeting:Create
、mobiletargeting:Update
和 mobiletargeting:Put
。這些是建立和管理大多數專案元件所需的額外許可。例如:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "LimitedWriteProject", "Effect": "Allow", "Action": "mobiletargeting:GetApps", "Resource": "arn:aws:mobiletargeting:
region
:accountId
:*" }, { "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*", "mobiletargeting:Create*", "mobiletargeting:Update*", "mobiletargeting:Put*" ], "Resource": [ "arn:aws:mobiletargeting:region
:accountId
:apps/810c7aab86d42fb2b56c8c966example", "arn:aws:mobiletargeting:region
:accountId
:apps/810c7aab86d42fb2b56c8c966example/*", "arn:aws:mobiletargeting:region
:accountId
:reports" ] }, { "Effect": "Allow", "Action": [ "ses:Get*", "kinesis:ListStreams", "firehose:ListDeliveryStreams", "iam:ListRoles", "ses:List*", "sns:ListTopics", "ses:Describe*", "s3:List*" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "accountId
" } } } ] }
範例:根據標籤檢視 Amazon Pinpoint 資源
您可以在身分型政策中使用條件,並根據標籤控制 Amazon Pinpoint 資源的存取權。此範例政策說明如何建立這類政策,才能允許檢視 Amazon Pinpoint 資源。但是,只有在資源標籤 Owner
的值是該使用者的使用者名稱時,才會授予該許可。此政策也會授予在主控台完成此動作的必要許可。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListResources", "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*" ], "Resource": "*" }, { "Sid": "ViewResourceIfOwner", "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*" ], "Resource": "arn:aws:mobiletargeting:*:*:*", "Condition": { "StringEquals": { "aws:ResourceTag/Owner": "
userName
" }, "StringEquals": { "aws:SourceAccount": "accountId
" }, "ArnLike": { "aws:SourceArn": "arn:aws:mobiletargeting:region
:accountId
:*" } } } ] }
您可以將此政策類型連接到您帳戶中的 使用者。如果 richard-roe
使用者嘗試檢視 Amazon Pinpoint 資源,必須將資源標記為 Owner=richard-roe
或 owner=richard-roe
。否則他便會被拒絕存取。條件標籤鍵 Owner
符合 Owner
和 owner
,因為條件索引鍵名稱不區分大小寫。如需詳細資訊,請參閱《IAM使用指南》中的IAMJSON策略元素:條件。
範例:允許使用者檢視他們自己的許可
此範例顯示如何建立原則,讓使IAM用者檢視附加至其使用者身分識別的內嵌和受管理原則。此原則包含在主控台上或以程式設計方式使用或完成此動作的 AWS CLI 權限 AWS API。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }
範例:提供對 Amazon 精確定位API動作的存取
本節提供範例政策,可讓您存取 Amazon Pinpoint 提供的功能API,這是 Amazon Pinpoint API 的主要功能。若要進一步了解API,請參閱 Amazon Pinpoint API 參考資料。
唯讀存取
下列範例政策允許以唯讀方式存取特定 AWS 區域中 Amazon Pinpoint 帳戶中的所有資源。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewAllResources", "Effect": "Allow", "Action": [ "mobiletargeting:Get*", "mobiletargeting:List*" ], "Resource": "arn:aws:mobiletargeting:
region
:accountId
:*" } ] }
在前面的例子中,替換 region
用一個 AWS 區域的名稱,並替換 accountId
使用您的 AWS
帳戶 ID。
管理員存取
以下範例政策可完全存取您 Amazon Pinpoint 帳戶中的所有 Amazon Pinpoint 動作和資源:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "FullAccess", "Effect": "Allow", "Action": [ "mobiletargeting:*" ], "Resource": "arn:aws:mobiletargeting:
region
:accountId
:*" } ] }
在前面的例子中,替換 accountId
使用您的 AWS 帳戶 ID。
範例:提供對 Amazon Pinpoint SMS 和語音API動作的存取
本節提供範例政策,可讓您存取 Amazon Pinpoint SMS 和語音API提供的功能。這是一項補充功API能,可提供在 Amazon Pinpoint 中使用和管理SMS和語音通道的進階選項。若要進一步了解這項功能API,請參閱 Amazon Pinpoint SMS 和語音API參考。
唯讀存取
下列範例政策允許對 AWS 帳戶中的所有 Amazon Pinpoint SMS 和語音API動作和資源進行唯讀存取:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "SMSVoiceReadOnly", "Effect": "Allow", "Action": [ "sms-voice:Get*", "sms-voice:List*" ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "
accountId
" }, "ArnLike": { "aws:SourceArn": "arn:aws:sms-voice:region
:accountId
:*" } } } ] }
管理員存取
下列範例政策可讓您完整存取 AWS 帳戶中的所有 Amazon Pinpoint SMS 和語音API動作和資源:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "SMSVoiceFullAccess", "Effect": "Allow", "Action": [ "sms-voice:*", ], "Resource": "*", "Condition": { "StringEquals": { "aws:SourceAccount": "
accountId
" }, "ArnLike": { "aws:SourceArn": "arn:aws:sms-voice:region
:accountId
:*" } } } ] }
範例:限制 Amazon Pinpoint 專案存取特定 IP 地址
下列範例政策授予任何使用者在指定專案上執行任何 Amazon Pinpoint 動作的許可 (projectId
). 不過,要求必須來自條件中指定的 IP 位址範圍。
此陳述式中的條件會識別允許的網際網路通訊協定第 4 版 (IPv4) 位址54.240.143.*
範圍,但有一個例外:54.240.143.188
。Condition
區塊會使用 AND NotIpAddress
條件IpAddress
和條aws:SourceIp
件索引鍵,這是一個 AWS寬度條件索引鍵。如需有關這些條件索引鍵的詳細資訊,請參閱在原則IAM使用指南中指定條件。這aws:SourceIp
IPv4些值使用標準CIDR符號。如需詳細資訊,請參閱《IAM使用指南》中的 IP 位址條件運算子。
{ "Version":"2012-10-17", "Id":"AMZPinpointPolicyId1", "Statement":[ { "Sid":"IPAllow", "Effect":"Allow", "Principal":"*", "Action":"mobiletargeting:*", "Resource":[ "arn:aws:mobiletargeting:
region
:accountId
:apps/projectId
", "arn:aws:mobiletargeting:region
:accountId
:apps/projectId
/*" ], "Condition":{ "IpAddress":{ "aws:SourceIp":"54.240.143.0/24" }, "NotIpAddress":{ "aws:SourceIp":"54.240.143.188/32" } } } ] }
範例:根據標籤限制 Amazon Pinpoint 存取權
下列範例政策授予對指定專案執行任何 Amazon Pinpoint 動作的許可 (projectId
). 不過,只有當要求來自名稱為專案Owner
資源標籤中值的使用者 (如條件中所指定) 時,才會授與權限。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ModifyResourceIfOwner", "Effect": "Allow", "Action": "mobiletargeting:*", "Resource": [ "arn:aws:mobiletargeting:
region
:accountId
:apps/projectId
", "arn:aws:mobiletargeting:region
:accountId
:apps/projectId
/*" ], "Condition": { "StringEquals": { "aws:ResourceTag/Owner": "userName
" } } } ] }
範例:允許 Amazon Pinpoint 使用在 Amazon 驗證的身分傳送電子郵件 SES
當您透過 Amazon Pinpoint 主控台驗證電子郵件身分 (例如電子郵件地址或網域) 時,系統會自動設定該身分,以便 Amazon Pinpoint 和 Amazon 兩者都可以使用該身分。SES但是,如果您透過 Amazon 驗證電子郵件身分SES,並且想要將該身分與 Amazon Pinpoint 搭配使用,則必須對該身分套用政策。
下列範例政策授予 Amazon Pinpoint 使用透過 Amazon SES 驗證的電子郵件身分傳送電子郵件的權限。
{ "Version":"2008-10-17", "Statement":[ { "Sid":"PinpointEmail", "Effect":"Allow", "Principal":{ "Service":"pinpoint.amazonaws.com" }, "Action":"ses:*", "Resource":"arn:aws:ses:
region
:accountId
:identity/emailId
", "Condition":{ "StringEquals":{ "aws:SourceAccount":"accountId
" }, "StringLike":{ "aws:SourceArn":"arn:aws:mobiletargeting:region
:accountId
:apps/*
" } } } ] }
如果您在 AWS GovCloud (美國西部) 區域使用 Amazon Pinpoint,請改用下列政策範例:
{ "Version":"2008-10-17", "Statement":[ { "Sid":"PinpointEmail", "Effect":"Allow", "Principal":{ "Service":"pinpoint.amazonaws.com" }, "Action":"ses:*", "Resource":"arn:aws-us-gov:ses:us-gov-west-1:
accountId
:identity/emailId
", "Condition":{ "StringEquals":{ "aws:SourceAccount":"accountId
" }, "StringLike":{ "aws:SourceArn":"arn:aws-us-gov:mobiletargeting:us-gov-west-1:accountId
:apps/*
" } } } ] }