Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add validations for export name in CfnOutput #28575

Merged
merged 8 commits into from
Jan 23, 2024
12 changes: 10 additions & 2 deletions packages/aws-cdk-lib/core/lib/cfn-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,16 @@ export class CfnOutput extends CfnElement {
}

private validateOutput(): string[] {
if (this._exportName && !Token.isUnresolved(this._exportName) && this._exportName.length > 255) {
return [`Export name cannot exceed 255 characters (got ${this._exportName.length} characters)`];
if (this._exportName !== undefined && !Token.isUnresolved(this._exportName)) {
if (this._exportName.length === 0) {
return ['Export name cannot be empty'];
}
if (this._exportName.length > 255) {
return [`Export name cannot exceed 255 characters (got ${this._exportName.length} characters)`];
}
if (!/^[A-Za-z0-9-:]*$/.test(this._exportName)) {
return [`Export name must only include alphanumeric characters, colons, or hyphens (got '${this._exportName}')`];
}
}
return [];
}
Expand Down
Loading