Skip to content

Bedrock Agentcore Control  >  Operations  >  create_policy

create_policy

Operation

create_policy async

create_policy(input: CreatePolicyInput, plugins: list[Plugin] | None = None) -> CreatePolicyOutput

Creates a policy within the AgentCore Policy system. Policies provide real-time, deterministic control over agentic interactions with AgentCore Gateway. Using the Cedar policy language, you can define fine-grained policies that specify which interactions with Gateway tools are permitted based on input parameters and OAuth claims, ensuring agents operate within defined boundaries and business rules. The policy is validated during creation against the Cedar schema generated from the Gateway's tools' input schemas, which defines the available tools, their parameters, and expected data types. This is an asynchronous operation. Use the GetPolicy operation to poll the status field to track completion.

Parameters:

Name Type Description Default
input CreatePolicyInput

An instance of CreatePolicyInput.

required
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
CreatePolicyOutput

An instance of CreatePolicyOutput.

Input

CreatePolicyInput dataclass

Dataclass for CreatePolicyInput structure.

Attributes

client_token class-attribute instance-attribute
client_token: str | None = None

A unique, case-sensitive identifier to ensure the idempotency of the request. The AWS SDK automatically generates this token, so you don't need to provide it in most cases. If you retry a request with the same client token, the service returns the same response without creating a duplicate policy.

definition class-attribute instance-attribute
definition: PolicyDefinition | None = None

The Cedar policy statement that defines the access control rules. This contains the actual policy logic written in Cedar policy language, specifying effect (permit or forbid), principals, actions, resources, and conditions for agent behavior control.

description class-attribute instance-attribute
description: str | None = field(repr=False, default=None)

A human-readable description of the policy's purpose and functionality (1-4,096 characters). This helps policy administrators understand the policy's intent, business rules, and operational scope. Use this field to document why the policy exists, what business requirement it addresses, and any special considerations for maintenance. Clear descriptions are essential for policy governance, auditing, and troubleshooting.

enforcement_mode class-attribute instance-attribute
enforcement_mode: EnforcementMode = EnforcementMode('ACTIVE')

The enforcement mode for the policy. Run this policy in LOG_ONLY mode to collect data on how it affects your application. Once you are satisfied with the data gathered, switch the policy to ACTIVE. Defaults to ACTIVE.

name class-attribute instance-attribute
name: str | None = None

The customer-assigned immutable name for the policy. Must be unique within the account. This name is used for policy identification and cannot be changed after creation.

policy_engine_id class-attribute instance-attribute
policy_engine_id: str | None = None

The identifier of the policy engine which contains this policy. Policy engines group related policies and provide the execution context for policy evaluation.

validation_mode class-attribute instance-attribute
validation_mode: PolicyValidationMode = PolicyValidationMode('FAIL_ON_ANY_FINDINGS')

The validation mode for the policy creation. Determines how Cedar analyzer validation results are handled during policy creation. FAIL_ON_ANY_FINDINGS (default) runs the Cedar analyzer to validate the policy against the Cedar schema and tool context, failing creation if the analyzer detects any validation issues to ensure strict conformance. IGNORE_ALL_FINDINGS runs the Cedar analyzer but allows policy creation even if validation issues are detected, useful for testing or when the policy schema is evolving. Use FAIL_ON_ANY_FINDINGS for production policies to ensure correctness, and IGNORE_ALL_FINDINGS only when you understand and accept the analyzer findings.

Output

CreatePolicyOutput dataclass

Dataclass for CreatePolicyOutput structure.

Attributes

created_at instance-attribute
created_at: datetime

The timestamp when the policy was created. This is automatically set by the service and used for auditing and lifecycle management.

definition instance-attribute
definition: PolicyDefinition

The Cedar policy statement that was created. This is the validated policy definition that will be used for agent behavior control and access decisions.

description class-attribute instance-attribute
description: str | None = field(repr=False, default=None)

The human-readable description of the policy's purpose and functionality. This helps administrators understand and manage the policy.

enforcement_mode class-attribute instance-attribute
enforcement_mode: EnforcementMode = EnforcementMode('ACTIVE')

The enforcement mode of the created policy.

name instance-attribute
name: str

The customer-assigned name of the created policy. This matches the name provided in the request and serves as the human-readable identifier for the policy.

policy_arn instance-attribute
policy_arn: str

The Amazon Resource Name (ARN) of the created policy. This globally unique identifier can be used for cross-service references and IAM policy statements.

policy_engine_id instance-attribute
policy_engine_id: str

The identifier of the policy engine that manages this policy. This confirms the policy engine assignment and is used for policy evaluation routing.

policy_id instance-attribute
policy_id: str

The unique identifier for the created policy. This is a system-generated identifier consisting of the user name plus a 10-character generated suffix, used for all subsequent policy operations.

status instance-attribute
status: PolicyStatus

The current status of the policy. A status of ACTIVE indicates the policy is ready for use.

status_reasons instance-attribute
status_reasons: list[str]

Additional information about the policy status. This provides details about any failures or the current state of the policy creation process.

updated_at instance-attribute
updated_at: datetime

The timestamp when the policy was last updated. For newly created policies, this matches the createdAt timestamp.