

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

# 搭配資源型政策使用 CloudWatch RUM
<a name="CloudWatch-RUM-resource-policies"></a>

您可以將資源政策連結至 CloudWatch RUM 應用程式監視器。根據預設，應用程式監視器不會連結資源政策。CloudWatch RUM 資源型政策不支援跨帳戶存取權。

若要進一步了解 AWS 資源政策，請參閱[身分型政策和資源型政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html)。

如需如何評估資源政策和身分政策的詳細資訊，請參閱[政策評估邏輯](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html)。

如需了解 IAM 政策文法的詳細資訊，請參閱 [IAM JSON 政策元素參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html)。

## 支援的動作
<a name="RUM-resource-policies-actions"></a>

應用程式監視器上的資源型政策支援 `rum:PutRumEvents` 動作。

## 要搭配 CloudWatch RUM 使用的政策範例
<a name="RUM-resource-policies-samples"></a>

下列範例允許任何人將資料寫入您的應用程式監視器，包括沒有 SigV4 憑證的人。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "rum:PutRumEvents",
            "Resource": "arn:aws:rum:{{us-east-1}}:{{123456789012}}:appmonitor/{{app monitor name}}",
            "Principal": "*"
        }
    ]
}
```

------

您可以使用 `aws:SourceIp` 條件金鑰修改政策以封鎖指定的來源 IP 位址。在此範例中，使用此政策時，來自所列 IP 位址的 PutRumEvents 將會遭到拒絕。系統會接受來自其他 IP 位址的所有其他請求。如需此條件金鑰的詳細資訊，請參閱《IAM 使用者指南》中的[網路屬性](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-network-properties)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "rum:PutRumEvents",
            "Resource": "arn:aws:rum:{{us-east-1}}:{{123456789012}}:appmonitor/{{AppMonitorName}}",
            "Principal": "*"
        },
        {
            "Effect": "Deny",
            "Action": "rum:PutRumEvents",
            "Resource": "arn:aws:rum:{{us-east-1}}:{{123456789012}}:appmonitor/{{AppMonitorName}}",
            "Principal": "*",
            "Condition": {
                "NotIpAddress": {
                "aws:SourceIp": "{{198.51.100.252}}"
                }
            }
        }
    ]
}
```

------

此外，您可以使用`rum:alias`服務內容金鑰來控制接受的請求。

對於 Web 應用程式監控，您必須將 Web 用戶端設定為`Alias`使用 1.20 版或更新版本的 CloudWatch RUM Web 用戶端傳送，如 GitHub [ 上的應用程式特定組態](https://github.com/aws-observability/aws-rum-web/blob/main/docs/configuration.md)中所述。

對於行動應用程式監視器，您必須根據 SDK 設定檢測。
+ iOS 應用程式使用 [AWS Distro for OpenTelemetry (ADOT) iOS 開發套件](https://github.com/aws-observability/aws-otel-swift)。
+ Android 應用程式使用 [AWS Distro for OpenTelemetry (ADOT) Android SDK](https://github.com/aws-observability/aws-otel-android)。

在下列範例中，資源政策要求請求必須包含 `alias1`或 `alias2` 才能接受事件。

```
    {
    "Version":"2012-10-17",                   
    "Statement": [
        {
            "Sid": "AllowRUMPutEvents",
            "Effect": "Allow",
            "Action": "rum:PutRumEvents",
            "Resource": "arn:aws:rum:us-east-1:123456789012:appmonitor/MyApplication",
            "Principal": "*",
            "Condition": {
                "StringEquals": {
                    "rum:alias":["alias1", "alias2"]
                }
            }
        }
    ]
}
```