Skip to content

Commit 7d22b2c

Browse files
authored
fix(python): Make sure stack name does not contain illegal characters (#3261)
* Make sure stack name does not contain illegal characters * Fix name and type of scope passed to Stacks
1 parent 0c30f12 commit 7d22b2c

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

packages/aws-cdk/lib/init-templates/app/python/%name.PythonModule%/%name.PythonModule%_stack.template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class %name.PascalCased%Stack(core.Stack):
55

6-
def __init__(self, app: core.App, id: str, **kwargs) -> None:
7-
super().__init__(app, id, **kwargs)
6+
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
7+
super().__init__(scope, id, **kwargs)
88

99
# The code that defines your stack goes here

packages/aws-cdk/lib/init-templates/app/python/app.template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77

88
app = core.App()
9-
%name.PascalCased%Stack(app, "%name%-cdk-1")
9+
%name.PascalCased%Stack(app, "%name.StackName%")
1010

1111
app.synth()

packages/aws-cdk/lib/init-templates/sample-app/python/hello/hello_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class MyStack(core.Stack):
1313

14-
def __init__(self, app: core.App, id: str, **kwargs) -> None:
15-
super().__init__(app, id, **kwargs)
14+
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
15+
super().__init__(scope, id, **kwargs)
1616

1717
queue = sqs.Queue(
1818
self, "MyFirstQueue",

packages/aws-cdk/lib/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export class InitTemplate {
154154
.replace(/%cdk-version%/g, cdkVersion)
155155
.replace(/%cdk-home%/g, CDK_HOME)
156156
.replace(/%name\.PythonModule%/g, project.name.replace(/-/g, '_'))
157-
.replace(/%python-executable%/g, pythonExecutable());
157+
.replace(/%python-executable%/g, pythonExecutable())
158+
.replace(/%name\.StackName%/g, project.name.replace(/[^A-Za-z0-9-]/g, '-'));
158159
}
159160
}
160161

0 commit comments

Comments
 (0)