Skip to content

Commit d7b27b5

Browse files
Initial update to CDKv2 (#1)
* Initial update to CDKv2 Imports adjusted - updated requirements files - replacement of aws_cdk.core with aws_cdk - import new constructs module Cleared cdk context values Updated aws-cdk CLI to compatible version * Removed ignored pylint options * Replaced cdk-chalice with chalice[cdkv2] As cdk-chalice has not been updated for cdkv2 yet, chalice[cdkv2] provides an alternative implementation for these constructs. However, this breaks the current tests. Bumped pip-tools for requirements resolution * Pinned flake8 to prevent dependency conflict flake8>=4.0 pins importlib-metadata<4.3 as a dependency. This is incompatible with other packages requiring importlib-metadata>=4.12. * Resolved pylint W1514: unspecified encoding * Updated token values in chalice config
1 parent e6e3c30 commit d7b27b5

19 files changed

+202
-3145
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[MESSAGES CONTROL]
2-
disable = C0330, C0326, C0111
2+
disable = C0111

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cd aws-cdk-project-structure-python
3232
python3.7 -m venv .venv
3333
source .venv/bin/activate
3434
# [Optional] Needed to upgrade dependencies and cleanup unused packages
35-
pip install pip-tools==6.1.0
35+
pip install pip-tools==6.8.0
3636
./scripts/install-deps.sh
3737
./scripts/run-tests.sh
3838
```

api/infrastructure.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
import pathlib
1717
from typing import Any, Dict
1818

19-
import cdk_chalice
19+
import aws_cdk as cdk
20+
import chalice.cdk
2021
from aws_cdk import aws_dynamodb as dynamodb
2122
from aws_cdk import aws_iam as iam
22-
from aws_cdk import core as cdk
23+
from constructs import Construct
2324

2425

25-
class API(cdk.Construct):
26+
class API(Construct):
2627
def __init__(
2728
self,
28-
scope: cdk.Construct,
29+
scope: Construct,
2930
id_: str,
3031
*,
3132
dynamodb_table: dynamodb.Table,
@@ -51,7 +52,7 @@ def __init__(
5152
handler_role, dynamodb_table, lambda_reserved_concurrency
5253
)
5354
source_dir = pathlib.Path(__file__).resolve().parent.joinpath("runtime")
54-
self.chalice = cdk_chalice.Chalice(
55+
self.chalice = chalice.cdk.Chalice(
5556
self,
5657
"Chalice",
5758
source_dir=str(source_dir),

api/runtime/.chalice/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"lambda_functions": {
88
"api_handler": {
99
"manage_iam_role": false,
10-
"iam_role_arn": "${Token[TOKEN.95]}",
10+
"iam_role_arn": "${Token[TOKEN.221]}",
1111
"environment_variables": {
12-
"TABLE_NAME": "${Token[TOKEN.86]}"
12+
"TABLE_NAME": "${Token[TOKEN.213]}"
1313
},
1414
"reserved_concurrency": 1
1515
}
@@ -20,9 +20,9 @@
2020
"lambda_functions": {
2121
"api_handler": {
2222
"manage_iam_role": false,
23-
"iam_role_arn": "${Token[TOKEN.142]}",
23+
"iam_role_arn": "${Token[TOKEN.269]}",
2424
"environment_variables": {
25-
"TABLE_NAME": "${Token[TOKEN.133]}"
25+
"TABLE_NAME": "${Token[TOKEN.261]}"
2626
},
2727
"reserved_concurrency": 10
2828
}

api/runtime/requirements.txt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#
2-
# This file is autogenerated by pip-compile
2+
# This file is autogenerated by pip-compile with python 3.7
33
# To update, run:
44
#
55
# pip-compile api/runtime/requirements.in
66
#
7-
attrs==20.3.0
7+
attrs==21.4.0
88
# via chalice
9-
blessed==1.17.6
9+
blessed==1.19.1
1010
# via inquirer
11-
boto3==1.18.4
11+
boto3==1.24.37
1212
# via -r api/runtime/requirements.in
13-
botocore==1.21.4
13+
botocore==1.27.37
1414
# via
1515
# boto3
1616
# chalice
1717
# s3transfer
18-
chalice==1.24.0
18+
chalice==1.27.1
1919
# via -r api/runtime/requirements.in
20-
click==7.1.2
20+
click==8.1.3
2121
# via chalice
22-
inquirer==2.7.0
22+
importlib-metadata==4.12.0
23+
# via click
24+
inquirer==2.9.2
2325
# via chalice
24-
jmespath==0.10.0
26+
jmespath==1.0.1
2527
# via
2628
# boto3
2729
# botocore
@@ -32,23 +34,27 @@ python-dateutil==2.8.2
3234
# via botocore
3335
python-editor==1.0.4
3436
# via inquirer
35-
pyyaml==5.4.1
37+
pyyaml==6.0
3638
# via chalice
37-
readchar==2.0.1
39+
readchar==3.1.0
3840
# via inquirer
39-
s3transfer==0.5.0
41+
s3transfer==0.6.0
4042
# via boto3
4143
six==1.16.0
4244
# via
4345
# blessed
4446
# chalice
4547
# python-dateutil
46-
urllib3==1.26.6
48+
typing-extensions==4.3.0
49+
# via importlib-metadata
50+
urllib3==1.26.11
4751
# via botocore
4852
wcwidth==0.2.5
4953
# via blessed
50-
wheel==0.36.2
54+
wheel==0.37.1
5155
# via chalice
56+
zipp==3.8.1
57+
# via importlib-metadata
5258

5359
# The following packages are considered to be unsafe in a requirements file:
5460
# pip

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1414
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1515

16-
from aws_cdk import core as cdk
16+
import aws_cdk as cdk
1717

1818
import constants
1919
from deployment import UserManagementBackend

cdk.context.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
{
2-
"@aws-cdk/core:enableStackNameDuplicates": "true",
3-
"@aws-cdk/core:newStyleStackSynthesis": "true"
42
}

constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import os
1717

18+
import aws_cdk as cdk
1819
from aws_cdk import aws_dynamodb as dynamodb
19-
from aws_cdk import core as cdk
2020

2121
CDK_APP_NAME = "UserManagementBackend"
2222
CDK_APP_PYTHON_VERSION = "3.7"

database/infrastructure.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1414
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1515

16+
import aws_cdk as cdk
1617
from aws_cdk import aws_dynamodb as dynamodb
17-
from aws_cdk import core as cdk
18+
from constructs import Construct
1819

1920

20-
class Database(cdk.Construct):
21+
class Database(Construct):
2122
def __init__(
2223
self,
23-
scope: cdk.Construct,
24+
scope: Construct,
2425
id_: str,
2526
*,
26-
dynamodb_billing_mode: dynamodb.BillingMode
27+
dynamodb_billing_mode: dynamodb.BillingMode,
2728
):
2829
super().__init__(scope, id_)
2930

deployment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
from typing import Any
1717

18+
import aws_cdk as cdk
1819
from aws_cdk import aws_dynamodb as dynamodb
19-
from aws_cdk import core as cdk
20+
from constructs import Construct
2021

2122
from api.infrastructure import API
2223
from database.infrastructure import Database
@@ -26,7 +27,7 @@
2627
class UserManagementBackend(cdk.Stage):
2728
def __init__(
2829
self,
29-
scope: cdk.Construct,
30+
scope: Construct,
3031
id_: str,
3132
*,
3233
database_dynamodb_billing_mode: dynamodb.BillingMode,

monitoring/infrastructure.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1414
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1515

16+
import aws_cdk as cdk
1617
from aws_cdk import aws_cloudwatch as cloudwatch
17-
from aws_cdk import aws_sam as sam
18-
from aws_cdk import core as cdk
18+
from constructs import Construct
1919

2020
from api.infrastructure import API
2121
from database.infrastructure import Database
2222

2323

24-
class Monitoring(cdk.Construct):
25-
def __init__(self, scope: cdk.Construct, id_: str, *, database: Database, api: API):
24+
class Monitoring(Construct):
25+
def __init__(self, scope: Construct, id_: str, *, database: Database, api: API):
2626
super().__init__(scope, id_)
2727

28-
apigateway: sam.CfnApi = api.chalice.sam_template.get_resource("RestAPI")
28+
apigateway: cdk.CfnResource = api.chalice.sam_template.get_resource("RestAPI")
2929
apigateway_metric_dimensions = {"ApiName": cdk.Fn.ref(apigateway.logical_id)}
3030
apigateway_metric_count = cloudwatch.Metric(
3131
namespace="AWS/APIGateway",
3232
metric_name="Count",
33-
dimensions=apigateway_metric_dimensions,
33+
dimensions_map=apigateway_metric_dimensions,
3434
)
3535
widgets = [
3636
cloudwatch.SingleValueWidget(metrics=[apigateway_metric_count]),

0 commit comments

Comments
 (0)