Package Exports
- agentcore-experimental-constructs
- agentcore-experimental-constructs/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (agentcore-experimental-constructs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
AgentCore Experimental CDK L2 Constructs
Experimental CDK Construct Library for Amazon Bedrock AgentCore using Custom Resources.
⚠️ For quick experimentation, Not for production use. Breaking changes expected when official L1 constructs are released and abstraction is re-implemented in @aws-cdk/aws-bedrock-agentcore-alpha.
Overview
This library provides experimental CDK constructs for Amazon Bedrock AgentCore services, including:
- Policy Engine: Define and manage Cedar-based authorization policies
- Cedar Policy Builder: Fluent API for creating Cedar policy statements
Installation
npm install agentcore-experimental-constructsUsage Examples
import { App, CfnOutput, Stack, StackProps } from 'aws-cdk-lib';
import { Function, Runtime, Code } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import {
CedarPolicy,
CedarAction,
CedarEffect,
CedarPrincipal,
CedarResource,
PolicyEngine,
ValidationMode,
} from 'agentcore-experimental-constructs';
import { Gateway, ToolSchema } from '@aws-cdk/aws-bedrock-agentcore-alpha';
import * as path from 'path';
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
const gateway = new Gateway(this, 'Gateway', {
gatewayName: 'test-gateway',
description: 'Test gateway',
});
const lambda = new Function(this, 'Lambda', {
runtime: Runtime.NODEJS_20_X,
handler: 'index.handler',
code: Code.fromAsset('lambda'),
});
const lambdaTarget = gateway.addLambdaTarget('lambda', {
gatewayTargetName: 'weather-lambda',
lambdaFunction: lambda,
toolSchema: ToolSchema.fromLocalAsset(path.join(__dirname, 'lambda', 'lambda_tool_schema.json')),
});
const engine = new PolicyEngine(this, 'PolicyEngine', {
name: 'test_policy_engine',
description: 'Test policy engine',
});
engine.addPolicy({
name: 'test_policy',
description: 'Test policy',
policyDefinition: CedarPolicy.fromPolicyStatement({
effect: CedarEffect.PERMIT,
principal: CedarPrincipal.anyOAuthUser(),
action: CedarAction.specificTool(lambdaTarget, 'getWeather'),
resource: CedarResource.gateway(gateway),
when: ['principal.hasTag("username")'],
unless: ['context.input.city == "London"'],
}),
validationMode: ValidationMode.IGNORE_ALL_FINDINGS,
});
new CfnOutput(this, 'GatewayArn', { value: gateway.gatewayArn });
new CfnOutput(this, 'GatewayUrl', { value: gateway.gatewayUrl! });
new CfnOutput(this, 'EngineArn', { value: engine.policyEngineArn });
new CfnOutput(this, 'EngineId', { value: engine.policyEngineId });
}
}
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: 'us-east-1',
};
const app = new App();
new MyStack(app, 'agentcore-policy-dev', { env: devEnv });
app.synth();Limitations
- Experimental: API may change without notice
- Custom Resources: Uses CloudFormation custom resources for AWS API calls
- Region Support: Limited to regions where AgentCore is available
- Breaking Changes: Expected when official L1 constructs are released
Contributing
This is an experimental library. Contributions are welcome but expect significant changes as the official CDK constructs become available.
License
Apache 2.0