18 // S3バケット読み込み s3 = boto3.session.Session().resource('s3') bucket_name = os.environ['ALERT_LOG_BUCKET'] bucket = s3.Bucket(bucket_name) key = os.environ['ALERT_LOG_KEY'] object = bucket.Object(key) last_updated_time_str = object.get()['Body'].read().decode('utf-8') result = int(last_updated_time_str) ... // S3バケット書き込み object = bucket.Object(key) object.put( Body=str(last_exec_time).encode('utf-8'), ContentEncoding='utf-8', ContentType='text/plain‘ ) S3呼び出し function_name = os.environ['FILTERED_ALERT_LOGS'] lambda_client = boto3.session.Session().client('lambda') lambda_client.invoke( FunctionName=function_name, InvocationType='Event', LogType='Tail', Payload=json.dumps(request) ) Lambda呼び出し // ロググループの取得 client = boto3.session.Session().client('logs') response = client.describe_log_groups( logGroupNamePrefix=prefix ) ... // ログストリームの取得 response = client.describe_log_streams( logGroupName=group_name, orderBy='LastEventTime', descending=True, limit=limit ) ... // ログイベントの取得 logs = client.get_log_events( logGroupName=group_name, logStreamName=stream_name, startTime=start_time, endTime=end_time, startFromHead=True ) CloudWatch呼び出し message = '整形したCloudWatchログ‘ topic_arn = os.environ['ALERT_LOG_TOPIC_ARN'] subject = os.environ['ALERT_LOG_SUBJECT'] sns_request_params = { 'TopicArn': topic_arn, 'Message': message, 'Subject': subject } sns_client = boto3.session.Session().client('sns') sns_client.publish(**sns_request_params) SNS呼び出し