Skip to content

Commit

Permalink
fix(python): Make sure stack name does not contain illegal characters (
Browse files Browse the repository at this point in the history
…#3261)

* Make sure stack name does not contain illegal characters

* Fix name and type of scope passed to Stacks
  • Loading branch information
garnaat authored Jul 9, 2019
1 parent 0c30f12 commit 7d22b2c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

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

# The code that defines your stack goes here
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@


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

app.synth()
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

class MyStack(core.Stack):

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

queue = sqs.Queue(
self, "MyFirstQueue",
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export class InitTemplate {
.replace(/%cdk-version%/g, cdkVersion)
.replace(/%cdk-home%/g, CDK_HOME)
.replace(/%name\.PythonModule%/g, project.name.replace(/-/g, '_'))
.replace(/%python-executable%/g, pythonExecutable());
.replace(/%python-executable%/g, pythonExecutable())
.replace(/%name\.StackName%/g, project.name.replace(/[^A-Za-z0-9-]/g, '-'));
}
}

Expand Down

0 comments on commit 7d22b2c

Please sign in to comment.