

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

# `AWSSupport-TroubleshootS3EventNotifications`
<a name="awssupport-troubleshoot-s3-event-notifications"></a>

 **Description** 

 `AWSSupport-TroubleshootS3EventNotifications` AWS Systems Manager 自動化 Runbook 可協助疑難排解使用 AWS Lambda 函數、Amazon Simple Notification Service (Amazon S3) 儲存貯體事件通知。 Amazon SNS Amazon SQS 它提供使用 Amazon S3 儲存貯體設定為目的地事件通知之不同資源的組態設定報告。

 **如何運作？** 

 Runbook 會執行下列步驟：
+ 檢查 Amazon S3 儲存貯體是否存在於`AWSSupport-TroubleshootS3EventNotifications`執行 的相同帳戶中。
+ 使用 [GetBucketNotificationConfiguration](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketNotificationConfiguration.html) API 擷取設定為 Amazon S3 儲存貯體事件通知的目的地資源 (AWS Lambda 函數或 Amazon SNS 主題或 Amazon SQS 佇列）。
+ 驗證目的地資源是否存在，然後檢閱目的地資源的資源型政策，以判斷是否允許 Amazon S3 發佈至目的地。
+ 如果您使用 AWS Key Management Service (AWS KMS) 金鑰加密目的地，則會檢查金鑰政策，以判斷是否允許 Amazon S3 存取。
+ 產生所有目的地資源檢查的報告。

**重要**  
只有在 Amazon S3 儲存貯體擁有者與執行自動化 Runbook 的 AWS 帳戶 擁有者相同時，此 Runbook 才能評估事件通知組態。
此外，此 Runbook 無法評估在另一個 中託管之目的地資源的政策 AWS 帳戶。

 [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/automation/execute/AWSSupport-TroubleshootS3EventNotifications) 

**文件類型**

 自動化

**擁有者**

Amazon

**平台**

Linux、macOS、 Windows

**參數**
+ AutomationAssumeRole

  類型：字串

  描述：（選用） 允許 Systems Manager Automation 代表您執行動作的 (IAM) 角色的 AWS Identity and Access Management Amazon Resource Name (ARN)。如果未指定角色，Systems Manager Automation 會使用啟動此 Runbook 之使用者的許可。
+ S3BucketName

  類型：`AWS::S3::Bucket::Name`

  描述：（必要） 使用事件通知設定的 Amazon S3 儲存貯體名稱 （含）。

**必要的 IAM 許可**

`AutomationAssumeRole` 參數需要下列動作才能成功使用 Runbook。
+ `s3:GetBucketLocation`
+ `s3:ListAllMyBuckets`
+ `s3:GetBucketNotification`
+ `sqs:GetQueueAttributes`
+ `sqs:GetQueueUrl`
+ `sns:GetTopicAttributes `
+ `kms:GetKeyPolicy`
+ `kms:DescribeKey`
+ `kms:ListAliases`
+ `lambda:GetPolicy`
+ `lambda:GetFunction`
+ `iam:GetContextKeysForCustomPolicy`
+ `iam:SimulateCustomPolicy`
+ `iam:ListRoles`
+ `ssm:DescribeAutomationStepExecutions`

 **自動化擔任角色的 IAM 政策範例** 

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

****  

```
                    {
                        "Version":"2012-10-17",		 	 	 
                        "Statement": [
                            {   
                                "Sid": "S3Permission",
                                "Effect": "Allow",
                                "Action": [
                                    "s3:GetBucketLocation",
                                    "s3:ListAllMyBuckets"
                                ],
                                "Resource": "*"
                            },
                            {   
                                "Sid": "S3PermissionGetBucketNotification",
                                "Effect": "Allow",
                                "Action": [
                                    "s3:GetBucketNotification"
                                ],
                                "Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
                            },
                            {
                                "Sid": "SQSPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "sqs:GetQueueAttributes",
                                    "sqs:GetQueueUrl"
                                ],
                                "Resource": "arn:aws:sqs:us-east-1:111122223333:*"
                            },
                            {
                                "Sid": "SNSPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "sns:GetTopicAttributes"
                                ],
                                "Resource": "arn:aws:sns:us-east-1:111122223333:*"
                            },
                            {   
                            "Sid": "KMSPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "kms:GetKeyPolicy",
                                    "kms:DescribeKey",
                                    "kms:ListAliases"
                                ],
                                "Resource": "arn:aws:kms:us-east-1:111122223333:key/key-id"
                            },
                            {
                                "Sid": "LambdaPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "lambda:GetPolicy",
                                    "lambda:GetFunction"
                                ],
                                "Resource": "arn:aws:lambda:us-east-1:111122223333:function:*"
                            },
                            {
                                "Sid": "IAMPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "iam:GetContextKeysForCustomPolicy",
                                    "iam:SimulateCustomPolicy",
                                    "iam:ListRoles"
                                ],
                                "Resource": "*"
                            },
                            {
                                "Sid": "SSMPermission",
                                "Effect": "Allow",
                                "Action": [
                                    "ssm:DescribeAutomationStepExecutions"
                                ],
                                "Resource": "*"
                            }
                        ]
                    }
```

------

 **指示** 

請依照下列步驟設定自動化：

1. 在文件下的 Systems Manager [https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootS3EventNotifications/description](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootS3EventNotifications/description)中導覽至 。

1. 選擇 Execute automation (執行自動化)。

1. 針對輸入參數，輸入下列內容：
   + **AutomationAssumeRole （選用）：**

     (IAM) 角色的 Amazon Resource Name AWS AWS Identity and Access Management (ARN)，允許 Systems Manager Automation 代表您執行動作。如果未指定角色，Systems Manager Automation 會使用啟動此 Runbook 之使用者的許可。
   + **S3BucketName （必要）：**

     使用事件通知 (Amazon S3) 設定的 Amazon S3 儲存貯體名稱。  
![\[AWSSupport-TroubleshootS3EventNotification Runbook 執行輸入參數。\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-s3-event-notifications_input_parameters.png)

1. 選取執行。

1. 自動化會啟動。

1. 文件會執行下列步驟：
   + **ValidateInputs**

     驗證提供的 Amazon S3 儲存貯體屬於執行自動化的相同帳戶，並擷取儲存貯體託管的區域。
   + **GetBucketNotificationConfiguration**

     呼叫 `GetBucketNotificationConfiguration` API 來檢閱使用 Amazon S3 儲存貯體設定的事件通知，並格式化輸出。
   + **BranchOnSQSResourcePolicy**

     有關事件通知中是否有 Amazon SQS 資源的分支。
   + **ValidateSQSResourcePolicy**

     驗證 Amazon SQS 佇列屬性上的資源政策具有 Amazon S3 的`sqs:SendMessage`許可。如果 Amazon SQS 資源已加密， 會檢查加密是否未使用預設 AWS KMS 金鑰，即 ，`aws/sqs`並檢查 AWS KMS 金鑰政策是否具有 Amazon S3 的許可。
   + **BranchOnSNSResourcePolicy**

     有關事件通知中是否有 Amazon SNS 資源的分支。
   + **ValidateSNSResourcePolicy**

     驗證 Amazon SNS 主題屬性上的資源政策具有 Amazon S3 的`sns:Publish`許可。如果 Amazon SNS 資源已加密， 會檢查加密是否未使用預設 AWS KMS 金鑰，即 ，`aws/sns`並檢查 AWS KMS 金鑰政策是否具有 Amazon S3 的許可。
   + **BranchOnLambdaFunctionResourcePolicy**

     有關事件通知中是否有 AWS Lambda 函數的分支。
   + **ValidateLambdaFunctionResourcePolicy**

     驗證 AWS Lambda 函數上的資源政策具有 Amazon S3 的`lambda:InvokeFunction`許可。
   + **GenerateReport**

     傳回 Runbook 步驟輸出的詳細資訊，以及解決使用 Amazon S3 儲存貯體設定之事件通知的任何問題的建議。

1. 完成後，請檢閱輸出區段以取得執行的詳細結果：
   + **Amazon SQS 事件通知**

     如果使用 Amazon SQSAmazon S3 目的地通知，Amazon SQS 佇列的清單會與檢查結果一起顯示。報告包括 Amazon SQS 資源檢查、Amazon SQS 存取政策檢查、 AWS KMS 金鑰檢查、 AWS KMS 金鑰狀態檢查和 AWS KMS 金鑰政策檢查。
   + **Amazon SNS 事件通知**

     如果有使用 Amazon S3 儲存貯體設定的 Amazon SNS 目的地通知，Amazon SNS 主題清單會與檢查結果一起顯示。 Amazon S3 報告包含 Amazon SNS 資源檢查、Amazon SNS 存取政策檢查、 AWS KMS 金鑰檢查、 AWS KMS 金鑰狀態檢查和 AWS KMS 金鑰政策檢查。
   + **AWS Lambda 事件通知**

     如果有使用 Amazon S3 儲存貯體設定的 AWS Lambda 目的地通知，則 Lambda 函數清單會與檢查結果一起顯示。報告包含 Lambda 資源檢查和 Lambda 存取政策檢查。  
![\[AWSSupport-TroubleshootS3EventNotification Runbook 範例執行輸出。\]](http://docs.aws.amazon.com/zh_tw/systems-manager-automation-runbooks/latest/userguide/images/awssupport-troubleshoot-s3-event-notifications_outputs.png)

 **參考** 

Systems Manager Automation
+ [執行此自動化 （主控台）](https://console.aws.amazon.com/systems-manager/documents/AWSSupport-TroubleshootS3EventNotifications/description)
+ [執行自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-working-executing.html)
+ [設定自動化](https://docs.aws.amazon.com//systems-manager/latest/userguide/automation-setup.html)
+ [支援自動化工作流程登陸頁面](https://aws.amazon.com/premiumsupport/technology/saw/)