Skip to content
v2.278.0

PolicyEngineMode Class ​

The enforcement mode for a policy engine associated with a gateway.

Example ​

ts

// Create a Policy engine
const policyEngine = new agentcore.PolicyEngine(this, "MyPolicyEngine", {
  policyEngineName: "my_policy_engine",
  description: "Policy engine for access control",
});

const gateway = new agentcore.Gateway(this, "MyGateway", {
  gatewayName: "my-gateway",
  policyEngineConfiguration: {
    policyEngine: policyEngine,
    mode: agentcore.PolicyEngineMode.ENFORCE, // Default is LOG_ONLY
  },
});

// Add policy to policy engine
policyEngine.addPolicy("AllowAllActions", {
  definition: `
    permit(
      principal,
      action,
      resource == AgentCore::Gateway::"${gateway.gatewayArn}"
    );
  `,
  description: "Allow all actions on specific gateway (development)",
  validationMode: agentcore.PolicyValidationMode.IGNORE_ALL_FINDINGS, // This will ignore all cedar warnings
});

// you can add multiple policies to the policy engine
policyEngine.addPolicy("SpecificToolPolicy", {
  definition: `
    permit(
      principal is AgentCore::OAuthUser,
      action == AgentCore::Action::"WeatherTool__get_forecast",
      resource == AgentCore::Gateway::"${gateway.gatewayArn}"
    );
  `,
  description: "Allow specific weather tool access",
  validationMode: agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS, // This will fail policy creation for any cedar warning
});
python
# Create a Policy engine
policy_engine = agentcore.PolicyEngine(self, "MyPolicyEngine",
    policy_engine_name="my_policy_engine",
    description="Policy engine for access control"
)

gateway = agentcore.Gateway(self, "MyGateway",
    gateway_name="my-gateway",
    policy_engine_configuration=agentcore.GatewayPolicyEngineConfig(
        policy_engine=policy_engine,
        mode=agentcore.PolicyEngineMode.ENFORCE
    )
)

# Add policy to policy engine
policy_engine.add_policy("AllowAllActions",
    definition=f"""
        permit(
          principal,
          action,
          resource == AgentCore::Gateway::\"{gateway.gatewayArn}\"
        );
      """,
    description="Allow all actions on specific gateway (development)",
    validation_mode=agentcore.PolicyValidationMode.IGNORE_ALL_FINDINGS
)

# you can add multiple policies to the policy engine
policy_engine.add_policy("SpecificToolPolicy",
    definition=f"""
        permit(
          principal is AgentCore::OAuthUser,
          action == AgentCore::Action::\"WeatherTool__get_forecast\",
          resource == AgentCore::Gateway::\"{gateway.gatewayArn}\"
        );
      """,
    description="Allow specific weather tool access",
    validation_mode=agentcore.PolicyValidationMode.FAIL_ON_ANY_FINDINGS
)
java
// Create a Policy engine
PolicyEngine policyEngine = PolicyEngine.Builder.create(this, "MyPolicyEngine")
        .policyEngineName("my_policy_engine")
        .description("Policy engine for access control")
        .build();

Gateway gateway = Gateway.Builder.create(this, "MyGateway")
        .gatewayName("my-gateway")
        .policyEngineConfiguration(GatewayPolicyEngineConfig.builder()
                .policyEngine(policyEngine)
                .mode(PolicyEngineMode.ENFORCE)
                .build())
        .build();

// Add policy to policy engine
policyEngine.addPolicy("AllowAllActions", AddPolicyOptions.builder()
        .definition(String.format("%n    permit(%n      principal,%n      action,%n      resource == AgentCore::Gateway::\"%s\"%n    );%n  ", gateway.getGatewayArn()))
        .description("Allow all actions on specific gateway (development)")
        .validationMode(PolicyValidationMode.IGNORE_ALL_FINDINGS)
        .build());

// you can add multiple policies to the policy engine
policyEngine.addPolicy("SpecificToolPolicy", AddPolicyOptions.builder()
        .definition(String.format("%n    permit(%n      principal is AgentCore::OAuthUser,%n      action == AgentCore::Action::\"WeatherTool__get_forecast\",%n      resource == AgentCore::Gateway::\"%s\"%n    );%n  ", gateway.getGatewayArn()))
        .description("Allow specific weather tool access")
        .validationMode(PolicyValidationMode.FAIL_ON_ANY_FINDINGS)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Agentcore.Alpha
// Create a Policy engine
var policyEngine = new PolicyEngine(this, "MyPolicyEngine", new PolicyEngineProps {
    PolicyEngineName = "my_policy_engine",
    Description = "Policy engine for access control"
});

var gateway = new Gateway(this, "MyGateway", new GatewayProps {
    GatewayName = "my-gateway",
    PolicyEngineConfiguration = new GatewayPolicyEngineConfig {
        PolicyEngine = policyEngine,
        Mode = PolicyEngineMode.ENFORCE
    }
});

// Add policy to policy engine
policyEngine.AddPolicy("AllowAllActions", new AddPolicyOptions {
    Definition = $@"
        permit(
          principal,
          action,
          resource == AgentCore::Gateway::""{gateway.gatewayArn}""
        );
      ",
    Description = "Allow all actions on specific gateway (development)",
    ValidationMode = PolicyValidationMode.IGNORE_ALL_FINDINGS
});

// you can add multiple policies to the policy engine
policyEngine.AddPolicy("SpecificToolPolicy", new AddPolicyOptions {
    Definition = $@"
        permit(
          principal is AgentCore::OAuthUser,
          action == AgentCore::Action::""WeatherTool__get_forecast"",
          resource == AgentCore::Gateway::""{gateway.gatewayArn}""
        );
      ",
    Description = "Allow specific weather tool access",
    ValidationMode = PolicyValidationMode.FAIL_ON_ANY_FINDINGS
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2
// Create a Policy engine
policyEngine := agentcore.NewPolicyEngine(this, jsii.String("MyPolicyEngine"), &PolicyEngineProps{
	PolicyEngineName: jsii.String("my_policy_engine"),
	Description: jsii.String("Policy engine for access control"),
})

gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
	GatewayName: jsii.String("my-gateway"),
	PolicyEngineConfiguration: &GatewayPolicyEngineConfig{
		PolicyEngine: policyEngine,
		Mode: agentcore.PolicyEngineMode_ENFORCE(),
	},
})

// Add policy to policy engine
policyEngine.AddPolicy(jsii.String("AllowAllActions"), &AddPolicyOptions{
	Definition: fmt.Sprintf("\n    permit(\n      principal,\n      action,\n      resource == AgentCore::Gateway::\"%v\"\n    );\n  ", gateway.GatewayArn),
	Description: jsii.String("Allow all actions on specific gateway (development)"),
	ValidationMode: agentcore.PolicyValidationMode_IGNORE_ALL_FINDINGS(),
})

// you can add multiple policies to the policy engine
policyEngine.AddPolicy(jsii.String("SpecificToolPolicy"), &AddPolicyOptions{
	Definition: fmt.Sprintf("\n    permit(\n      principal is AgentCore::OAuthUser,\n      action == AgentCore::Action::\"WeatherTool__get_forecast\",\n      resource == AgentCore::Gateway::\"%v\"\n    );\n  ", gateway.*GatewayArn),
	Description: jsii.String("Allow specific weather tool access"),
	ValidationMode: agentcore.PolicyValidationMode_FAIL_ON_ANY_FINDINGS(),
})

Initializer ​

ts
new PolicyEngineMode(value: string)
python
PolicyEngineMode(value: str)
java
new PolicyEngineMode(String value)
csharp
new PolicyEngineMode(string value)
go
NewPolicyEngineMode(Value *string)

Properties ​

Enforces decisions by allowing or denying agent operations based on Cedar policies.
Evaluates actions and adds traces but does not enforce decisions.

Use this mode for testing and validation before enabling enforcement.

valuestringvaluestrvalueStringValuestringValue*string #
The string value of the policy engine mode.