Skip to content
v2.277.0

PolicyStatement Class ​

A Cedar authorization policy statement.

A statement names the principal, action and resource it applies to, and optionally conditions that narrow it further. All three parts are required, so a statement is complete as soon as it is constructed.

Example ​

ts
import { Policy, PolicyEngine, PolicyStatement } from 'aws-cdk-lib/aws-bedrockagentcore';
declare const engine: PolicyEngine;

// Example 4: raw Cedar, for features the API does not model
new Policy(this, 'CustomPolicy', {
  policyEngine: engine,
  statement: PolicyStatement.fromCedar('permit(principal, action, resource) when { context.custom > 10 };'),
});
python
from aws_cdk.aws_bedrockagentcore import Policy, PolicyEngine, PolicyStatement
# engine: PolicyEngine


# Example 4: raw Cedar, for features the API does not model
Policy(self, "CustomPolicy",
    policy_engine=engine,
    statement=PolicyStatement.from_cedar("permit(principal, action, resource) when { context.custom > 10 };")
)
java
import software.amazon.awscdk.services.bedrockagentcore.Policy;
import software.amazon.awscdk.services.bedrockagentcore.PolicyEngine;
import software.amazon.awscdk.services.bedrockagentcore.PolicyStatement;
PolicyEngine engine;


// Example 4: raw Cedar, for features the API does not model
// Example 4: raw Cedar, for features the API does not model
Policy.Builder.create(this, "CustomPolicy")
        .policyEngine(engine)
        .statement(PolicyStatement.fromCedar("permit(principal, action, resource) when { context.custom > 10 };"))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.BedrockAgentCore;
PolicyEngine engine;


// Example 4: raw Cedar, for features the API does not model
// Example 4: raw Cedar, for features the API does not model
new Policy(this, "CustomPolicy", new PolicyProps {
    PolicyEngine = engine,
    Statement = PolicyStatement.FromCedar("permit(principal, action, resource) when { context.custom > 10 };")
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
var engine PolicyEngine


// Example 4: raw Cedar, for features the API does not model
// Example 4: raw Cedar, for features the API does not model
awscdk.NewPolicy(this, jsii.String("CustomPolicy"), &PolicyProps{
	PolicyEngine: engine,
	Statement: awscdk.PolicyStatement_FromCedar(jsii.String("permit(principal, action, resource) when { context.custom > 10 };")),
})

Initializer ​

ts
new PolicyStatement(props: PolicyStatementProps)
python
PolicyStatement(props: PolicyStatementProps)
java
new PolicyStatement(PolicyStatementProps props)
csharp
new PolicyStatement(PolicyStatementProps props)
go
NewPolicyStatement(Props PolicyStatementProps)

Methods ​

fromCedar(cedarStatement: string): PolicyStatement // chainable@staticmethod def from_cedar(cedar_statement: str) -> PolicyStatementpublic static PolicyStatement fromCedar(String cedarStatement)public static PolicyStatement FromCedar(string cedarStatement)func FromCedar(CedarStatement *string) PolicyStatementstatic#
Create a statement from raw Cedar source.
notes · 1 parameter

Use this for Cedar features this API does not model, or to migrate an existing policy.

The source is used exactly as given. This method does not escape, quote, or validate it, so it is treated as trusted input and you own its correctness and its safety. Do not build the string by joining values that come from outside your application: a value containing a double quote can close a string literal early and add policy statements you did not write. Pass such values through PolicyCondition and the principal, action and resource factories instead, which reject that case at synthesis time. Service-side validation does not help, because an injected policy is still valid Cedar.

Parameters

  • cedarStatementcedar_statementcedarStatementcedarStatementCedarStatement — - Complete Cedar policy statement.
toCedar(): stringdef to_cedar(self, ) -> strpublic String toCedar()public string ToCedar()func ToCedar() *string#
Generate the Cedar policy statement string.

This is called internally by the Policy construct.

returns

Returns: Valid Cedar policy statement