Skip to content
GitHubXDiscord

AccountPolicy

The AccountPolicy resource allows you to manage AWS Logs AccountPolicys for your AWS account. This resource enables you to define logging policies to control access to log data across your AWS services.

Create a basic account policy with essential properties.

import AWS from "alchemy/aws/control";
const basicAccountPolicy = await AWS.Logs.AccountPolicy("basicAccountPolicy", {
PolicyType: "CLOUDWATCH_LOGS",
PolicyName: "BasicLoggingPolicy",
PolicyDocument: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: "logs:CreateLogGroup",
Resource: "*"
}]
})
});

Configure an account policy with additional options for selection criteria and scope.

const advancedAccountPolicy = await AWS.Logs.AccountPolicy("advancedAccountPolicy", {
PolicyType: "CLOUDWATCH_LOGS",
PolicyName: "AdvancedLoggingPolicy",
Scope: "Organization",
SelectionCriteria: "Region = 'us-west-2'",
PolicyDocument: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: "logs:*",
Resource: "*"
}]
})
});

Create a policy that includes specific conditions to restrict access based on account ID.

const restrictedAccountPolicy = await AWS.Logs.AccountPolicy("restrictedAccountPolicy", {
PolicyType: "CLOUDWATCH_LOGS",
PolicyName: "RestrictedLoggingPolicy",
PolicyDocument: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: "logs:DescribeLogGroups",
Resource: "*",
Condition: {
"StringEquals": {
"aws:PrincipalAccount": "123456789012"
}
}
}]
})
});

Adopt an existing account policy instead of failing if it already exists.

const adoptExistingPolicy = await AWS.Logs.AccountPolicy("adoptExistingPolicy", {
PolicyType: "CLOUDWATCH_LOGS",
PolicyName: "AdoptedLoggingPolicy",
PolicyDocument: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: "logs:PutLogEvents",
Resource: "*"
}]
}),
adopt: true
});