createLogGroup method
Creates a log group with the specified name. You can create up to 1,000,000 log groups per Region per account.
You must use the following guidelines when naming a log group:
- Log group names must be unique within a Region for an Amazon Web Services account.
- Log group names can be between 1 and 512 characters long.
- Log group names consist of the following characters: a-z, A-Z, 0-9, '_' (underscore), '-' (hyphen), '/' (forward slash), '.' (period), and '#' (number sign)
-
Log group names can't start with the string
aws/
If you associate an KMS key with the log group, ingested data is encrypted using the KMS key. This association is stored as long as the data encrypted with the KMS key is still within CloudWatch Logs. This enables CloudWatch Logs to decrypt this data whenever it is requested.
If you attempt to associate a KMS key with the log group but the KMS key
does not exist or the KMS key is disabled, you receive an
InvalidParameterException error.
May throw InvalidParameterException.
May throw LimitExceededException.
May throw OperationAbortedException.
May throw ResourceAlreadyExistsException.
May throw ServiceUnavailableException.
Parameter logGroupName :
A name for the log group.
Parameter deletionProtectionEnabled :
Use this parameter to enable deletion protection for the new log group.
When enabled on a log group, deletion protection blocks all deletion
operations until it is explicitly disabled. By default log groups are
created without deletion protection enabled.
Parameter kmsKeyId :
The Amazon Resource Name (ARN) of the KMS key to use when encrypting log
data. For more information, see Amazon
Resource Names.
Parameter logGroupClass :
Use this parameter to specify the log group class for this log group.
There are three classes:
-
The
Standardlog class supports all CloudWatch Logs features. -
The
Infrequent Accesslog class supports a subset of CloudWatch Logs features and incurs lower costs. -
Use the
Deliverylog class only for delivering Lambda logs to store in Amazon S3 or Amazon Data Firehose. Log events in log groups in the Delivery class are kept in CloudWatch Logs for only one day. This log class doesn't offer rich CloudWatch Logs capabilities such as CloudWatch Logs Insights queries.
STANDARD is used.
For details about the features supported by each class, see Log
classes
Parameter tags :
The key-value pairs to use for the tags.
You can grant users access to certain log groups while preventing them
from accessing other log groups. To do so, tag your groups and use IAM
policies that refer to those tags. To assign tags when you create a log
group, you must have either the logs:TagResource or
logs:TagLogGroup permission. For more information about
tagging, see Tagging
Amazon Web Services resources. For more information about using tags
to control access, see Controlling
access to Amazon Web Services resources using tags.
Implementation
Future<void> createLogGroup({
required String logGroupName,
bool? deletionProtectionEnabled,
String? kmsKeyId,
LogGroupClass? logGroupClass,
Map<String, String>? tags,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Logs_20140328.CreateLogGroup'
};
await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'logGroupName': logGroupName,
if (deletionProtectionEnabled != null)
'deletionProtectionEnabled': deletionProtectionEnabled,
if (kmsKeyId != null) 'kmsKeyId': kmsKeyId,
if (logGroupClass != null) 'logGroupClass': logGroupClass.value,
if (tags != null) 'tags': tags,
},
);
}