8000 Initial update to CDKv2 by jgreenbow-userful · Pull Request #1 · aws-samples/aws-cdk-project-structure-python · GitHub
[go: up one dir, main page]

Skip to content

Initial update to CDKv2 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable = C0330, C0326, C0111
disable = C0111
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cd aws-cdk-project-structure-python
python3.7 -m venv .venv
source .venv/bin/activate
# [Optional] Needed to upgrade dependencies and cleanup unused packages
pip install pip-tools==6.1.0
pip install pip-tools==6.8.0
./scripts/install-deps.sh
./scripts/run-tests.sh
```
Expand Down
11 changes: 6 additions & 5 deletions api/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
import pathlib
from typing import Any, Dict

import cdk_chalice
import aws_cdk as cdk
import chalice.cdk
from aws_cdk import aws_dynamodb as dynamodb
from aws_cdk import aws_iam as iam
from aws_cdk import core as cdk
from constructs import Construct


class API(cdk.Construct):
class API(Construct):
def __init__(
self,
scope: cdk.Construct,
scope: Construct,
id_: str,
*,
dynamodb_table: dynamodb.Table,
Expand All @@ -51,7 +52,7 @@ def __init__(
handler_role, dynamodb_table, lambda_reserved_concurrency
)
source_dir = pathlib.Path(__file__).resolve().parent.joinpath("runtime")
self.chalice = cdk_chalice.Chalice(
self.chalice = chalice.cdk.Chalice(
self,
"Chalice",
source_dir=str(source_dir),
Expand Down
8 changes: 4 additions & 4 deletions api/runtime/.chalice/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"lambda_functions": {
"api_handler": {
"manage_iam_role": false,
"iam_role_arn": "${Token[TOKEN.95]}",
"iam_role_arn": "${Token[TOKEN.221]}",
"environment_variables": {
"TABLE_NAME": "${Token[TOKEN.86]}"
"TABLE_NAME": "${Token[TOKEN.213]}"
},
"reserved_concurrency": 1
}
Expand All @@ -20,9 +20,9 @@
"lambda_functions": {
"api_handler": {
"manage_iam_role": false,
"iam_role_arn": "${Token[TOKEN.142]}",
"iam_role_arn": "${Token[TOKEN.269]}",
"environment_variables": {
"TABLE_NAME": "${Token[TOKEN.133]}"
"TABLE_NAME": "${Token[TOKEN.261]}"
},
"reserved_concurrency": 10
}
Expand Down
34 changes: 20 additions & 14 deletions api/runtime/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.7
# To update, run:
#
# pip-compile api/runtime/requirements.in
#
attrs==20.3.0
attrs==21.4.0
# via chalice
blessed==1.17.6
blessed==1.19.1
# via inquirer
boto3==1.18.4
boto3==1.24.37
# via -r api/runtime/requirements.in
botocore==1.21.4
botocore==1.27.37
# via
# boto3
# chalice
# s3transfer
chalice==1.24.0
chalice==1.27.1
# via -r api/runtime/requirements.in
click==7.1.2
click==8.1.3
# via chalice
inquirer==2.7.0
importlib-metadata==4.12.0
# via click
inquirer==2.9.2
# via chalice
jmespath==0.10.0
jmespath==1.0.1
# via
# boto3
# botocore
Expand All @@ -32,23 +34,27 @@ python-dateutil==2.8.2
# via botocore
python-editor==1.0.4
# via inquirer
pyyaml==5.4.1
pyyaml==6.0
# via chalice
readchar==2.0.1
readchar==3.1.0
# via inquirer
s3transfer==0.5.0
s3transfer==0.6.0
# via boto3
six==1.16.0
# via
# blessed
# chalice
# python-dateutil
urllib3==1.26.6
typing-extensions==4.3.0
# via importlib-metadata
urllib3==1.26.11
# via botocore
wcwidth==0.2.5
# via blessed
wheel==0.36.2
wheel==0.37.1
# via chalice
zipp==3.8.1
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from aws_cdk import core as cdk
import aws_cdk as cdk

import constants
from deployment import UserManagementBackend
Expand Down
2 changes: 0 additions & 2 deletions cdk.context.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
{
"@aws-cdk/core:enableStackNameDuplicates": "true",
"@aws-cdk/core:newStyleStackSynthesis": "true"
}
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import os

import aws_cdk as cdk
from aws_cdk import aws_dynamodb as dynamodb
from aws_cdk import core as cdk

CDK_APP_NAME = "UserManagementBackend"
CDK_APP_PYTHON_VERSION = "3.7"
Expand Down
9 changes: 5 additions & 4 deletions database/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import aws_cdk as cdk
from aws_cdk import aws_dynamodb as dynamodb
from aws_cdk import core as cdk
from constructs import Construct


class Database(cdk.Construct):
class Database(Construct):
def __init__(
self,
scope: cdk.Construct,
scope: Construct,
id_: str,
*,
dynamodb_billing_mode: dynamodb.BillingMode
dynamodb_billing_mode: dynamodb.BillingMode,
):
super().__init__(scope, id_)

Expand Down
5 changes: 3 additions & 2 deletions deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

from typing import Any

import aws_cdk as cdk
from aws_cdk import aws_dynamodb as dynamodb
from aws_cdk import core as cdk
from constructs import Construct

from api.infrastructure import API
from database.infrastructure import Database
Expand All @@ -26,7 +27,7 @@
class UserManagementBackend(cdk.Stage):
def __init__(
self,
scope: cdk.Construct,
scope: Construct,
id_: str,
*,
database_dynamodb_billing_mode: dynamodb.BillingMode,
Expand Down
12 changes: 6 additions & 6 deletions monitoring/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import aws_cdk as cdk
from aws_cdk import aws_cloudwatch as cloudwatch
from aws_cdk import aws_sam as sam
from aws_cdk import core as cdk
from constructs import Construct

from api.infrastructure import API
from database.infrastructure import Database


class Monitoring(cdk.Construct):
def __init__(self, scope: cdk.Construct, id_: str, *, database: Database, api: API):
class Monitoring(Construct):
def __init__(self, scope: Construct, id_: str, *, database: Database, api: API):
super().__init__(scope, id_)

apigateway: sam.CfnApi = api.chalice.sam_template.get_resource("RestAPI")
apigateway: cdk.CfnResource = api.chalice.sam_template.get_resource("RestAPI")
apigateway_metric_dimensions = {"ApiName": cdk.Fn.ref(apigateway.logical_id)}
apigateway_metric_count = cloudwatch.Metric(
namespace="AWS/APIGateway",
metric_name="Count",
dimensions=apigateway_metric_dimensions,
dimensions_map=apigateway_metric_dimensions,
)
widgets = [
cloudwatch.SingleValueWidget(metrics=[apigateway_metric_count]),
Expand Down
Loading
0