core: Stage name check allows underscores ('_') and periods ('.') while stack name does not allow them
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
The following code
```ts
pipeline.addStage(new AppStage(this, "Stage per acme.example.com"));
```
results into the following `synth` error
```bash
Error: invalid stage name "Stage per acme.example.com". Stage name must start with a letter and contain only alphanumeric characters, hypens ('-'), underscores ('_') and periods ('.')
```
According to error message I can use underscores and periods. My next try with the code
```ts
pipeline.addStage(new AppStage(this, "Stage_per_acme.example.com"));
```
results into the following `synth` error
```bash
Error: Stack name must match the regular expression: /^[A-Za-z][A-Za-z0-9-]*$/, got 'Stage_per_acme.example.com-HelloCdkStack'
```
### Expected Behavior
Provide clear error message what characters are allowed for stage id.
### Current Behavior
Error message reads that underscores and periods are allowed for stage id but `synth` returns errors for those.
### Reproduction Steps
See https://github.com/yuyokk/aws-cdk-stage-name-bug/blob/main/lib/hello-cdk-stack.ts
```ts
// lib/hello-cdk-stack.ts
import { Stack, StackProps, Stage, StageProps } from "aws-cdk-lib";
import {
CodePipeline,
CodePipelineSource,
ShellStep,
} from "aws-cdk-lib/pipelines";
import { Construct } from "constructs";
export class PipelineStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const pipeline = new CodePipeline(this, "Pipeline", {
crossAccountKeys: true,
synth: new ShellStep("Synth", {
input: CodePipelineSource.gitHub("yuyokk/tenant-core", "main"),
commands: ["npm ci", "npm run build", "npx cdk synth"],
}),
});
pipeline.addStage(new AppStage(this, "Stage per acme.example.com"));
// pipeline.addStage(new AppStage(this, "Stage_per_acme.example.com"));
}
}
class AppStage extends Stage {
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
new HelloCdkStack(this, "HelloCdkStack");
}
}
class HelloCdkStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
}
}
```
```ts
// bin/hello-cdk.ts
#!/usr/bin/env node
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { PipelineStack } from "../lib/hello-cdk-stack";
const app = new cdk.App();
new PipelineStack(app, "HelloCdkStack");
```
### Possible Solution
Fix stage name check to be consistent with stack id checks.
PR for a possible fix https://github.com/aws/aws-cdk/pull/23089
### Additional Information/Context
_No response_
### CDK CLI Version
2.51.1
### Framework Version
_No response_
### Node.js Version
v16.18.1
### OS
macOS 13.0.1
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
The reproduction is in lib/hello-cdk-stack.ts, with the application entry point in bin/hello-cdk.ts; start by running the shown npm and npx cdk synth commands to reproduce the validation mismatch. Review PR #23089 before making changes, and consider the issue complete when stage-name guidance and synth behavior are consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100