Skip to content

Commit 2bff047

Browse files
committed
migrated to AWS CDK v2 (python)
1 parent 832499e commit 2bff047

File tree

5 files changed

+47
-88
lines changed

5 files changed

+47
-88
lines changed

lambda-sns-sms-cdk/app.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
#!/usr/bin/env python3
2-
import os
3-
4-
from aws_cdk import core as cdk
5-
6-
# For consistency with TypeScript code, `cdk` is the preferred import name for
7-
# the CDK's core module. The following line also imports it as `core` for use
8-
# with examples from the CDK Developer's Guide, which are in the process of
9-
# being updated to use `cdk`. You may delete this import if you don't need it.
10-
from aws_cdk import core
11-
2+
from aws_cdk import App
123
from lambda_sns_sms_cdk.lambda_sns_sms_cdk_stack import LambdaSnsSmsCdkStack
134

145

15-
app = core.App()
6+
app = App()
167
LambdaSnsSmsCdkStack(app, "LambdaSnsSmsCdkStack",
178
# If you don't specify 'env', this stack will be environment-agnostic.
189
# Account/Region-dependent features and context lookups will not work,

lambda-sns-sms-cdk/cdk.json

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
{
22
"app": "python3 app.py",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"requirements*.txt",
11+
"source.bat",
12+
"**/__init__.py",
13+
"python/__pycache__",
14+
"tests"
15+
]
16+
},
317
"context": {
418
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
5-
"@aws-cdk/core:enableStackNameDuplicates": "true",
6-
"aws-cdk:enableDiffNoFail": "true",
7-
"@aws-cdk/core:stackRelativeExports": "true",
8-
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
9-
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
10-
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
11-
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true,
12-
"@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true,
19+
"@aws-cdk/core:stackRelativeExports": true,
1320
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
14-
"@aws-cdk/aws-efs:defaultEncryptionAtRest": true,
1521
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
16-
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true
22+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
23+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
24+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
25+
"@aws-cdk/core:target-partitions": [
26+
"aws",
27+
"aws-cn"
28+
]
1729
}
1830
}

lambda-sns-sms-cdk/lambda_sns_sms_cdk/lambda_sns_sms_cdk_stack.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
from aws_cdk import core as cdk
2-
from aws_cdk import aws_lambda
3-
from aws_cdk import aws_iam as iam
4-
from aws_cdk import aws_logs as logs
5-
6-
# For consistency with other languages, `cdk` is the preferred import name for
7-
# the CDK's core module. The following line also imports it as `core` for use
8-
# with examples from the CDK Developer's Guide, which are in the process of
9-
# being updated to use `cdk`. You may delete this import if you don't need it.
10-
from aws_cdk import core
11-
12-
13-
class LambdaSnsSmsCdkStack(cdk.Stack):
14-
15-
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
1+
from aws_cdk import (
2+
Stack,
3+
RemovalPolicy,
4+
Duration,
5+
CfnParameter,
6+
CfnOutput,
7+
aws_lambda,
8+
aws_iam as iam,
9+
aws_logs as logs
10+
)
11+
from constructs import Construct
12+
13+
14+
class LambdaSnsSmsCdkStack(Stack):
15+
16+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
1617
super().__init__(scope, construct_id, **kwargs)
1718

18-
phoneNumber = core.CfnParameter(self, "phoneNumber", type="String",
19+
phoneNumber = CfnParameter(self, "phoneNumber", type="String",
1920
description="Recipient phone number")
20-
tenDLC = core.CfnParameter(self, "tenDLC", type="String",
21+
tenDLC = CfnParameter(self, "tenDLC", type="String",
2122
description="10DLC origination number")
2223

2324
# We create a log group so it will be gracefully cleaned up on a destroy event. By default
2425
# logs never expire and won't be removed.
2526
lambdaLogGroup = logs.LogGroup(self,
2627
'SMSPublisherFunctionLogGroup',
2728
log_group_name='/aws/lambda/SMSPublisherFunction',
28-
removal_policy=core.RemovalPolicy.DESTROY,
29+
removal_policy=RemovalPolicy.DESTROY,
2930
retention=logs.RetentionDays.FIVE_DAYS,
3031
)
3132

@@ -35,7 +36,7 @@ def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
3536
function_name='SMSPublisherFunction',
3637
handler='app.handler',
3738
runtime=aws_lambda.Runtime.NODEJS_12_X,
38-
timeout=core.Duration.seconds(3),
39+
timeout=Duration.seconds(3),
3940
memory_size=128,
4041
environment={'phoneNumber': phoneNumber.value_as_string,
4142
'tenDLC': tenDLC.value_as_string},
@@ -55,7 +56,7 @@ def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
5556
# Make sure the log group is created prior to the function so CDK doesn't create a new one
5657
SMSPublisherFunction.node.add_dependency(lambdaLogGroup)
5758

58-
core.CfnOutput(self,
59+
CfnOutput(self,
5960
'SMSPublisherFunctionName',
6061
description='SMSPublisherFunction function name',
6162
value=SMSPublisherFunction.function_name

lambda-sns-sms-cdk/requirements.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
aws_cdk.aws_logs
2-
aws_cdk.aws_lambda
3-
aws_cdk.aws_iam
4-
-e .
1+
aws-cdk-lib==2.13.0
2+
constructs>=10.0.0,<11.0.0

lambda-sns-sms-cdk/setup.py

-43
This file was deleted.

0 commit comments

Comments
 (0)