View a markdown version of this page

PutSyslogConfiguration 搭配 AWS SDK 使用 - Amazon CloudWatch Logs

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

PutSyslogConfiguration 搭配 AWS SDK 使用

以下程式碼範例顯示如何使用 PutSyslogConfiguration。

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

Python
適用於 Python 的 SDK (Boto3)
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

def put_syslog_configuration( self, log_group_identifier: str, vpc_endpoint_id: str ) -> None: """ Creates or updates a syslog configuration for a log group. This enables ingestion of syslog data through the specified VPC endpoint. :param log_group_identifier: The name or ARN of the log group to associate with the syslog configuration. :param vpc_endpoint_id: The ID of the VPC endpoint to use for syslog ingestion. :raises ClientError: If the log group or VPC endpoint does not exist. """ try: self.logs_client.put_syslog_configuration( logGroupIdentifier=log_group_identifier, vpcEndpointId=vpc_endpoint_id, ) logger.info( "Created syslog configuration for log group '%s' with VPC endpoint '%s'.", log_group_identifier, vpc_endpoint_id, ) except ClientError as error: if error.response["Error"]["Code"] == "ResourceNotFoundException": logger.error( "The specified log group or VPC endpoint does not exist: %s", error.response["Error"]["Message"], ) else: logger.error( "Failed to put syslog configuration: %s", error.response["Error"]["Message"], ) raise
  • 如需 API 詳細資訊,請參閱《適用於 AWS Python (Boto3) 的 SDK API 參考》中的 PutSyslogConfiguration。

如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用 CloudWatch Logs。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。