View a markdown version of this page

AWSSupport-CollectEKSInstanceLogs - AWS Systems Manager Automation Runbook 參考

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

AWSSupport-CollectEKSInstanceLogs

Description

AWSSupport-CollectEKSInstanceLogs Runbook 會從 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體收集作業系統和 Amazon Elastic Kubernetes Service (Amazon EKS) 相關日誌檔案,以協助您疑難排解常見問題。當自動化收集相關的日誌檔案時,會變更檔案系統結構,包括建立暫時目錄、將日誌檔案複製到暫時目錄,以及將日誌檔案壓縮至封存。此活動可能會導致 Amazon EC2 執行個體CPUUtilization增加。如需 CPUUtilization 的詳細資訊,請參閱《Amazon CloudWatch 使用者指南》中的執行個體指標

如果您指定 LogDestination 參數的值,自動化會評估您指定之 Amazon Simple Storage Service (Amazon S3) 儲存貯體的政策狀態。為了協助保護從 Amazon EC2 執行個體收集之日誌的安全性,如果政策狀態isPublic設定為 true ,或存取控制清單 (ACL) 將READ|WRITE許可授予 All Users Amazon S3 預先定義的群組,則不會上傳日誌。如需 Amazon S3 預先定義群組的詳細資訊,請參閱《Amazon Simple Storage Service 使用者指南》中的 Amazon S3 預先定義群組

注意

此自動化需要在連接至 Amazon EC2 執行個體的根 Amazon Elastic Block Store (Amazon EBS) 磁碟區上至少 10% 的可用磁碟空間。如果根磁碟區上的可用磁碟空間不足,自動化會停止。

執行此自動化 (主控台)

文件類型

 自動化

擁有者

Amazon

平台

Linux

參數

  • AutomationAssumeRole

    類型:字串

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

  • EKSInstanceId

    類型:字串

    描述:(必要) 您要從中收集日誌的 Amazon EKS Amazon EC2 執行個體 ID。

  • LogDestination

    類型:字串

    描述:(選用) 帳戶中要上傳封存日誌的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。

必要的 IAM 許可

AutomationAssumeRole 參數需要下列動作才能成功使用 Runbook。

  • ssm:StartAutomationExecution

  • ssm:GetAutomationExecution

  • ssm:SendCommand

Amazon EC2 執行個體描述檔所需的 IAM 許可

所使用的執行個體描述檔EKSInstanceId必須連接 AmazonSSMManagedInstanceCore Amazon 受管政策。

它也必須能夠存取 LogDestination Amazon S3 儲存貯體,才能上傳收集的日誌。以下是可以連接到該執行個體描述檔的 IAM 政策範例:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetBucketPolicyStatus", "s3:GetBucketAcl" ], "Resource": [ "arn:aws:s3:::LogDestination/*", "arn:aws:s3:::LogDestination" ] } ] }

如果 LogDestination使用 AWS KMS 加密,則必須將額外的陳述式新增至 IAM 政策,以授予加密所用 AWS KMS 金鑰的存取權:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetBucketPolicyStatus", "s3:GetBucketAcl" ], "Resource": [ "arn:aws:s3:::LogDestination/*", "arn:aws:s3:::LogDestination" ] }, { "Effect": "Allow", "Action": [ "kms:Decrypt", "kms:GenerateDataKey" ], "Resource": "arn:aws:kms:REGION:ACCOUNT:key/KMS-KEY-ID" } ] }

文件步驟

  • aws:assertAwsResourceProperty - 確認EKSInstanceId參數中指定值的作業系統為 Linux。

  • aws:runCommand - 收集作業系統和 Amazon EKS 相關日誌檔案,將其壓縮為 /var/log目錄中的封存。

  • aws:branch - 確認是否已為 LogDestination 參數指定值。

  • aws:runCommand - 將日誌封存上傳至您在 LogDestination 參數中指定的 Amazon S3 儲存貯體。