public function testCanCreateAndDeleteLogGroup() { $this->logs->createLogGroup(array('logGroupName' => 'foo')); $logGroups = $this->logs->getIterator('DescribeLogGroups'); $logGroups = iterator_to_array($logGroups); $this->assertCount(1, $logGroups); $this->logs->deleteLogGroup(array('logGroupName' => 'foo')); $logGroups = $this->logs->getIterator('DescribeLogGroups'); $logGroups = iterator_to_array($logGroups); $this->assertCount(0, $logGroups); }
private function initialize() { // fetch existing groups $existingGroups = $this->client->describeLogGroups(['logGroupNamePrefix' => $this->logGroupName])->get('logGroups'); // extract existing groups names $existingGroupsNames = array_map(function ($group) { return $group['logGroupName']; }, $existingGroups); // create group and set retention policy if not created yet if (!in_array($this->logGroupName, $existingGroupsNames, true)) { $this->client->createLogGroup(['logGroupName' => $this->logGroupName]); $this->client->putRetentionPolicy(['logGroupName' => $this->logGroupName, 'retentionInDays' => $this->retentionDays]); } // fetch existing streams $existingStreams = $this->client->describeLogStreams(['logGroupName' => $this->logGroupName, 'logStreamNamePrefix' => $this->logStreamName])->get('logStreams'); // extract existing streams names $existingStreamsNames = array_map(function ($stream) { // set sequence token if ($stream['logStreamName'] === $this->logStreamName && isset($stream['uploadSequenceToken'])) { $this->uploadSequenceToken = $stream['uploadSequenceToken']; } return $stream['logStreamName']; }, $existingStreams); // create stream if not created if (!in_array($this->logStreamName, $existingStreamsNames, true)) { $this->client->createLogStream(['logGroupName' => $this->logGroupName, 'logStreamName' => $this->logStreamName]); } $this->initialized = true; }