startPolicyGeneration method
Initiates the AI-powered generation of Cedar policies from natural language descriptions within the AgentCore Policy system. This feature enables both technical and non-technical users to create policies by describing their authorization requirements in plain English, which is then automatically translated into formal Cedar policy statements. The generation process analyzes the natural language input along with the Gateway's tool context to produce validated policy options. Generated policy assets are automatically deleted after 7 days, so you should review and create policies from the generated assets within this timeframe. Once created, policies are permanent and not subject to this expiration. Generated policies should be reviewed and tested in log-only mode before deploying to production. Use this when you want to describe policy intent naturally rather than learning Cedar syntax, though generated policies may require refinement for complex scenarios.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter content :
The natural language description of the desired policy behavior. This
content is processed by AI to generate corresponding Cedar policy
statements that match the described intent.
Parameter name :
A customer-assigned name for the policy generation request. This helps
track and identify generation operations, especially when running multiple
generations simultaneously.
Parameter policyEngineId :
The identifier of the policy engine that provides the context for policy
generation. This engine's schema and tool context are used to ensure
generated policies are valid and applicable.
Parameter resource :
The resource information that provides context for policy generation. This
helps the AI understand the target resources and generate appropriate
access control rules.
Parameter clientToken :
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 starting a duplicate
generation.
Implementation
Future<StartPolicyGenerationResponse> startPolicyGeneration({
required Content content,
required String name,
required String policyEngineId,
required Resource resource,
String? clientToken,
}) async {
final $payload = <String, dynamic>{
'content': content,
'name': name,
'resource': resource,
'clientToken': clientToken ?? _s.generateIdempotencyToken(),
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri:
'/policy-engines/${Uri.encodeComponent(policyEngineId)}/policy-generations',
exceptionFnMap: _exceptionFns,
);
return StartPolicyGenerationResponse.fromJson(response);
}