Skip to content
GitHubXDiscord

LogGroup

The LogGroup resource lets you manage AWS Logs LogGroups which act as containers for log streams that share the same retention, monitoring, and access control settings.

Create a basic LogGroup with a retention policy and a tag.

import AWS from "alchemy/aws/control";
const logGroup = await AWS.Logs.LogGroup("myLogGroup", {
logGroupName: "MyApplicationLogs",
retentionInDays: 14,
tags: [{
key: "Environment",
value: "Production"
}]
});

Configure a LogGroup with a custom KMS key and field index policies.

const secureLogGroup = await AWS.Logs.LogGroup("secureLogGroup", {
logGroupName: "SecureApplicationLogs",
kmsKeyId: "arn:aws:kms:us-west-2:123456789012:key/abcd1234-a123-456a-a12b-a123b4cd56ef",
fieldIndexPolicies: [{
field: "userId",
index: "true"
}],
retentionInDays: 30,
tags: [{
key: "Application",
value: "MySecureApp"
}]
});

Adopt an existing LogGroup instead of failing if it already exists.

const existingLogGroup = await AWS.Logs.LogGroup("existingLogGroup", {
logGroupName: "ExistingApplicationLogs",
adopt: true
});

Create a LogGroup with a data protection policy for enhanced security.

const protectedLogGroup = await AWS.Logs.LogGroup("protectedLogGroup", {
logGroupName: "ProtectedApplicationLogs",
dataProtectionPolicy: {
version: "2012-10-17",
statement: [{
effect: "Allow",
action: "logs:PutLogEvents",
resource: "arn:aws:logs:us-west-2:123456789012:log-group:ProtectedApplicationLogs:*",
condition: {
test: "StringEquals",
variable: "aws:username",
values: ["admin"]
}
}]
},
retentionInDays: 365
});