Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/cli/operations/deploy/preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function formatError(err: unknown): string {
* Also validates AWS credentials are configured before proceeding.
* Returns the project context needed for subsequent steps.
*/
const MAX_RUNTIME_NAME_LENGTH = 48;

export async function validateProject(): Promise<PreflightContext> {
// Find the agentcore config directory, walking up from cwd if needed
const configRoot = requireConfigRoot();
Expand All @@ -68,12 +70,35 @@ export async function validateProject(): Promise<PreflightContext> {
const projectSpec = await configIO.readProjectSpec();
const awsTargets = await configIO.readAWSDeploymentTargets();

// Validate runtime names don't exceed AWS limits
validateRuntimeNames(projectSpec);

// Validate AWS credentials before proceeding with build/synth
await validateAwsCredentials();

return { projectSpec, awsTargets, cdkProject };
}

/**
* Validates that combined runtime names (projectName_runtimeName) don't exceed AWS limits.
*/
function validateRuntimeNames(projectSpec: AgentCoreProjectSpec): void {
const projectName = projectSpec.name;
for (const agent of projectSpec.agents) {
const runtimeName = agent.runtime?.name;
if (runtimeName) {
const combinedName = `${projectName}_${runtimeName}`;
if (combinedName.length > MAX_RUNTIME_NAME_LENGTH) {
throw new Error(
`Runtime name too long: "${combinedName}" (${combinedName.length} chars). ` +
`AWS limits runtime names to ${MAX_RUNTIME_NAME_LENGTH} characters. ` +
`Shorten the project name or runtime.name in agentcore.json.`
);
}
}
}
}

/**
* Builds the CDK project.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/schema/schemas/agent-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export type Instrumentation = z.infer<typeof InstrumentationSchema>;
*/
const AgentRuntimeNameSchema = z
.string()
.min(1)
.max(48)
.min(1, 'Runtime name is required')
.max(23, 'Runtime name must be 23 characters or less (AWS runtime name limit)')
.regex(
/^[a-zA-Z][a-zA-Z0-9_]{0,47}$/,
'Must begin with a letter and contain only alphanumeric characters and underscores (max 48 chars)'
/^[a-zA-Z][a-zA-Z0-9_]{0,22}$/,
'Runtime name must start with a letter and contain only alphanumeric characters and underscores'
);

const CodeZipRuntimeSchema = z.object({
Expand Down
11 changes: 6 additions & 5 deletions src/schema/schemas/agentcore-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import { z } from 'zod';
/**
* Project name validation (CloudFormation logical ID compatible).
* Used in CloudFormation stack naming - must start with letter, alphanumeric only.
* Max 36 chars to allow room for suffixes in generated resource names.
* Max 23 chars because runtime names are generated as {projectName}_{runtimeName}
* and AWS limits agentRuntimeName to 48 characters total.
*
* Also validates against reserved names that would conflict with Python packages
* when creating virtual environments (e.g., 'openai', 'anthropic', 'langchain').
*/
export const ProjectNameSchema = z
.string()
.min(1)
.max(36)
.min(1, 'Project name is required')
.max(23, 'Project name must be 23 characters or less (AWS runtime name limit)')
.regex(
/^[A-Za-z][A-Za-z0-9]{0,35}$/,
'Must start with a letter and contain only alphanumeric characters (max 36 chars)'
/^[A-Za-z][A-Za-z0-9]{0,22}$/,
'Project name must start with a letter and contain only alphanumeric characters'
)
.refine(name => !isReservedProjectName(name), {
message: 'This name conflicts with a Python package dependency. Please choose a different name.',
Expand Down