Skip to content

Commit

Permalink
chore(init-templates): Python app template imports 'core' as 'cdk' to…
Browse files Browse the repository at this point in the history
… align sample code across languages (#12970)

For consistency and to make it easier to translate TypeScript examples into Python, import the `aws_cdk.core` module as `cdk`.

There are snippets in the CDK Developer Guide that assume the `core` module is imported as `core`. It is difficult to synchronize changes to the CDK with changes in the Guide, so this PR causes the `core` module to be imported under _both_ names. Once this change is released, the Guide snippets can be updated to use `cdk` rather than `core` to refer to the `core` module. At some point in the future, this template can be updated again to remove the now-redundant `core` import.

This is to support this Guide issue: awsdocs/aws-cdk-guide#268 which intends to make all code snippets in the Guide follow the guidance in the "Working with the CDK in Python" topic.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Jerry Kindall authored Feb 25, 2021
1 parent 430c38b commit c4a239c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from aws_cdk import core as cdk

# For consistency with other languages, `cdk` is the preferred import name for
# the CDK's core module. The following line also imports it as `core` for use
# with examples from the CDK Developer's Guide, which are in the process of
# being updated to use `cdk`. You may delete this import if you don't need it.
from aws_cdk import core


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

def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

# The code that defines your stack goes here
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/usr/bin/env python3

from aws_cdk import core as cdk

# For consistency with TypeScript code, `cdk` is the preferred import name for
# the CDK's core module. The following line also imports it as `core` for use
# with examples from the CDK Developer's Guide, which are in the process of
# being updated to use `cdk`. You may delete this import if you don't need it.
from aws_cdk import core

from %name.PythonModule%.%name.PythonModule%_stack import %name.PascalCased%Stack


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

app.synth()

0 comments on commit c4a239c

Please sign in to comment.