Skip to content

Commit aa40a57

Browse files
Merge pull request #535 from awslabs/python_and_example_updates
Update rdklib templates and support python 3.13
2 parents 61ce2dc + a5da068 commit aa40a57

File tree

15 files changed

+393
-56
lines changed

15 files changed

+393
-56
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ rdk init --generate-lambda-layer --custom-layer-name <LAYER_NAME>
9292

9393
In your working directory, use the `create` command to start creating a new custom rule. You must specify the runtime for the Lambda function that will back the Rule, and you can also specify a resource type (or comma-separated list of types) that the Rule will evaluate or a maximum frequency for a periodic rule. This will add a new directory for the rule and populate it with several files, including a skeleton of your Lambda code.
9494

95-
> :warning: By default, if you do not specify a runtime, `rdk` will select the latest `rdklib` Python runtime (eg. `python3.12-lib`). If you use an `rdklib` runtime, you will need to have `rdklib` Lambda layer installed in your AWS account (see `--generate-lambda-layer` in `rdk init` above), and will need `rdklib` installed locally if you plan to run unit tests locally. Alternatively, you can explicitly specify a non-`rdklib` runtime like `python3.12`.
95+
> :warning: By default, if you do not specify a runtime, `rdk` will select the latest `rdklib` Python runtime (eg. `python3.13-lib`). If you use an `rdklib` runtime, you will need to have `rdklib` Lambda layer installed in your AWS account (see `--generate-lambda-layer` in `rdk init` above), and will need `rdklib` installed locally if you plan to run unit tests locally. Alternatively, you can explicitly specify a non-`rdklib` runtime like `python3.13`.
9696
9797
```bash
98-
rdk create MyRule --runtime python3.12 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
98+
rdk create MyRule --runtime python3.13 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
9999
Running create!
100100
Local Rule files created.
101101
```
@@ -162,7 +162,7 @@ The test file includes setup for the MagicMock library that can be used to stub
162162
If you need to change the parameters of a Config rule in your working directory you can use the `modify` command. Any parameters you specify will overwrite existing values, any that you do not specify will not be changed.
163163
164164
```bash
165-
rdk modify MyRule --runtime python3.12 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
165+
rdk modify MyRule --runtime python3.13 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
166166
Running modify!
167167
Modified Rule 'MyRule'. Use the `deploy` command to push your changes to AWS.
168168
```
@@ -259,7 +259,7 @@ CloudFormation template written to remote-rule-template.json
259259
It is now possible to define a resource type that is not yet supported by `rdk`. To disable the supported resource check use the optional flag `--skip-supported-resource-check` during the create command.
260260
261261
```bash
262-
rdk create MyRule --runtime python3.12 --resource-types AWS::New::ResourceType --skip-supported-resource-check
262+
rdk create MyRule --runtime python3.13 --resource-types AWS::New::ResourceType --skip-supported-resource-check
263263
'AWS::New::ResourceType' not found in list of accepted resource types.
264264
Skip-Supported-Resource-Check Flag set (--skip-supported-resource-check), ignoring missing resource type error.
265265
Running create!
@@ -274,7 +274,7 @@ As of version 0.7.14, instead of defaulting the lambda function names to `RDK-Ru
274274
2. Custom lambda function naming as per personal or enterprise standards.
275275
276276
```bash
277-
rdk create MyLongerRuleName --runtime python3.12 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
277+
rdk create MyLongerRuleName --runtime python3.13 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
278278
Running create!
279279
Local Rule files created.
280280
```

docs/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ rdk init --generate-lambda-layer --custom-layer-name <LAYER_NAME>
9292

9393
In your working directory, use the `create` command to start creating a new custom rule. You must specify the runtime for the Lambda function that will back the Rule, and you can also specify a resource type (or comma-separated list of types) that the Rule will evaluate or a maximum frequency for a periodic rule. This will add a new directory for the rule and populate it with several files, including a skeleton of your Lambda code.
9494

95-
> :warning: By default, if you do not specify a runtime, `rdk` will select the latest `rdklib` Python runtime (eg. `python3.12-lib`). If you use an `rdklib` runtime, you will need to have `rdklib` Lambda layer installed in your AWS account (see `--generate-lambda-layer` in `rdk init` above), and will need `rdklib` installed locally if you plan to run unit tests locally. Alternatively, you can explicitly specify a non-`rdklib` runtime like `python3.12`.
95+
> :warning: By default, if you do not specify a runtime, `rdk` will select the latest `rdklib` Python runtime (eg. `python3.13-lib`). If you use an `rdklib` runtime, you will need to have `rdklib` Lambda layer installed in your AWS account (see `--generate-lambda-layer` in `rdk init` above), and will need `rdklib` installed locally if you plan to run unit tests locally. Alternatively, you can explicitly specify a non-`rdklib` runtime like `python3.13`.
9696
9797
```bash
98-
rdk create MyRule --runtime python3.12 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
98+
rdk create MyRule --runtime python3.13 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
9999
Running create!
100100
Local Rule files created.
101101
```
@@ -162,7 +162,7 @@ The test file includes setup for the MagicMock library that can be used to stub
162162
If you need to change the parameters of a Config rule in your working directory you can use the `modify` command. Any parameters you specify will overwrite existing values, any that you do not specify will not be changed.
163163
164164
```bash
165-
rdk modify MyRule --runtime python3.12 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
165+
rdk modify MyRule --runtime python3.13 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
166166
Running modify!
167167
Modified Rule 'MyRule'. Use the `deploy` command to push your changes to AWS.
168168
```
@@ -259,7 +259,7 @@ CloudFormation template written to remote-rule-template.json
259259
It is now possible to define a resource type that is not yet supported by `rdk`. To disable the supported resource check use the optional flag `--skip-supported-resource-check` during the create command.
260260
261261
```bash
262-
rdk create MyRule --runtime python3.12 --resource-types AWS::New::ResourceType --skip-supported-resource-check
262+
rdk create MyRule --runtime python3.13 --resource-types AWS::New::ResourceType --skip-supported-resource-check
263263
'AWS::New::ResourceType' not found in list of accepted resource types.
264264
Skip-Supported-Resource-Check Flag set (--skip-supported-resource-check), ignoring missing resource type error.
265265
Running create!
@@ -274,7 +274,7 @@ As of version 0.7.14, instead of defaulting the lambda function names to `RDK-Ru
274274
2. Custom lambda function naming as per personal or enterprise standards.
275275
276276
```bash
277-
rdk create MyLongerRuleName --runtime python3.12 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
277+
rdk create MyLongerRuleName --runtime python3.13 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
278278
Running create!
279279
Local Rule files created.
280280
```

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
88
[tool.poetry]
99
name = "rdk"
10-
version = "0.17.18"
10+
version = "0.17.19"
1111
description = "Rule Development Kit CLI for AWS Config"
1212
authors = [
1313
"AWS RDK Maintainers <[email protected]>",
@@ -28,6 +28,7 @@ classifiers = [
2828
"Programming Language :: Python :: 3.10",
2929
"Programming Language :: Python :: 3.11",
3030
"Programming Language :: Python :: 3.12",
31+
"Programming Language :: Python :: 3.13",
3132
]
3233
include = [
3334
"README.md",
@@ -55,6 +56,8 @@ include = [
5556
"rdk/template/runtime/python3.11-lib/*",
5657
"rdk/template/runtime/python3.12/*",
5758
"rdk/template/runtime/python3.12-lib/*",
59+
"rdk/template/runtime/python3.13/*",
60+
"rdk/template/runtime/python3.13-lib/*",
5861
"rdk/template/runtime/dotnetcore1.0/*",
5962
"rdk/template/runtime/dotnetcore1.0/bin/*",
6063
"rdk/template/runtime/dotnetcore1.0/obj/*",

rdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
#
77
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
88

9-
MY_VERSION = "0.17.18"
9+
MY_VERSION = "0.17.19"

rdk/rdk.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def get_rule_parser(is_required, command):
275275
"python3.11-lib",
276276
"python3.12",
277277
"python3.12-lib",
278+
"python3.13",
279+
"python3.13-lib",
278280
],
279281
metavar="",
280282
)
@@ -289,7 +291,7 @@ def get_rule_parser(is_required, command):
289291
required=False,
290292
help="[optional] Provide custom lambda name",
291293
)
292-
parser.set_defaults(runtime="python3.12-lib")
294+
parser.set_defaults(runtime="python3.13-lib")
293295
parser.add_argument(
294296
"-r",
295297
"--resource-types",
@@ -1238,6 +1240,8 @@ def create(self):
12381240
"python3.11-lib": ".py",
12391241
"python3.12": ".py",
12401242
"python3.12-lib": ".py",
1243+
"python3.13": ".py",
1244+
"python3.13-lib": ".py",
12411245
}
12421246
if self.args.runtime not in extension_mapping:
12431247
print("rdk does not support that runtime yet.")
@@ -1283,6 +1287,7 @@ def create(self):
12831287
"python3.10-lib",
12841288
"python3.11-lib",
12851289
"python3.12-lib",
1290+
"python3.13-lib",
12861291
]:
12871292
if self.args.resource_types:
12881293
applicable_resource_list = ""
@@ -2675,6 +2680,8 @@ def test_local(self):
26752680
"python3.11-lib",
26762681
"python3.12",
26772682
"python3.12-lib",
2683+
"python3.13",
2684+
"python3.13-lib",
26782685
):
26792686
print("Skipping " + rule_name + " - Runtime not supported for local testing.")
26802687
continue
@@ -3909,6 +3916,8 @@ def __get_handler(self, rule_name, params):
39093916
"python3.11-lib",
39103917
"python3.12",
39113918
"python3.12-lib",
3919+
"python3.13",
3920+
"python3.13-lib",
39123921
]:
39133922
return rule_name + ".lambda_handler"
39143923
elif params["SourceRuntime"] in ["java8"]:
@@ -3922,6 +3931,7 @@ def __get_runtime_string(self, params):
39223931
"python3.10-lib",
39233932
"python3.11-lib",
39243933
"python3.12-lib",
3934+
"python3.13-lib",
39253935
]:
39263936
runtime = params["SourceRuntime"].split("-")
39273937
return runtime[0]
@@ -4316,6 +4326,7 @@ def __get_lambda_layers(self, my_session, args, params):
43164326
"python3.10-lib",
43174327
"python3.11-lib",
43184328
"python3.12-lib",
4329+
"python3.13-lib",
43194330
]:
43204331
if hasattr(args, "generated_lambda_layer") and args.generated_lambda_layer:
43214332
lambda_layer_version = self.__get_existing_lambda_layer(
@@ -4449,6 +4460,7 @@ def __create_new_lambda_layer_locally(self, my_session, layer_name="rdklib-layer
44494460
"python3.10",
44504461
"python3.11",
44514462
"python3.12",
4463+
"python3.13",
44524464
],
44534465
)
44544466

rdk/template/runtime/python3.10-lib/rule_code.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType
22
<%ApplicableResources1%>
33
class <%RuleName%>(ConfigRule):
4+
# NOTE - you should typically only implement one of evaluate_change() or evaluate_periodic()!
5+
# If implementing a periodic rule, you will need to delete evaluate_change() and uncomment evaluate_periodic()
6+
47
def evaluate_change(self, event, client_factory, configuration_item, valid_rule_parameters):
5-
###############################
6-
# Add your custom logic here. #
7-
###############################
8+
################################################
9+
# Add your custom change-triggered logic here. #
10+
################################################
811

912
return [Evaluation(ComplianceType.NOT_APPLICABLE)]
1013

11-
#def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
12-
# pass
14+
15+
# def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
16+
# ########################################
17+
# # Add your custom periodic logic here. #
18+
# ########################################
19+
# # If you are evaluating resources that are not supported by the Config Service...
20+
# # ...it is often helpful to specify the account as the resource type/ID
21+
# account_id = event['accountId']
22+
# return [
23+
# Evaluation(
24+
# complianceType=ComplianceType.COMPLIANT,
25+
# resourceId=account_id,
26+
# resourceType="AWS::::Account",
27+
# annotation="Use this field to explain why this evaluation occurred.",
28+
# )
29+
# ]
30+
1331

1432
def evaluate_parameters(self, rule_parameters):
1533
valid_rule_parameters = rule_parameters

rdk/template/runtime/python3.11-lib/rule_code.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType
22
<%ApplicableResources1%>
33
class <%RuleName%>(ConfigRule):
4+
# NOTE - you should typically only implement one of evaluate_change() or evaluate_periodic()!
5+
# If implementing a periodic rule, you will need to delete evaluate_change() and uncomment evaluate_periodic()
6+
47
def evaluate_change(self, event, client_factory, configuration_item, valid_rule_parameters):
5-
###############################
6-
# Add your custom logic here. #
7-
###############################
8+
################################################
9+
# Add your custom change-triggered logic here. #
10+
################################################
811

912
return [Evaluation(ComplianceType.NOT_APPLICABLE)]
1013

11-
#def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
12-
# pass
14+
15+
# def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
16+
# ########################################
17+
# # Add your custom periodic logic here. #
18+
# ########################################
19+
# # If you are evaluating resources that are not supported by the Config Service...
20+
# # ...it is often helpful to specify the account as the resource type/ID
21+
# account_id = event['accountId']
22+
# return [
23+
# Evaluation(
24+
# complianceType=ComplianceType.COMPLIANT,
25+
# resourceId=account_id,
26+
# resourceType="AWS::::Account",
27+
# annotation="Use this field to explain why this evaluation occurred.",
28+
# )
29+
# ]
30+
1331

1432
def evaluate_parameters(self, rule_parameters):
1533
valid_rule_parameters = rule_parameters

rdk/template/runtime/python3.12-lib/rule_code.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType
22
<%ApplicableResources1%>
33
class <%RuleName%>(ConfigRule):
4+
# NOTE - you should typically only implement one of evaluate_change() or evaluate_periodic()!
5+
# If implementing a periodic rule, you will need to delete evaluate_change() and uncomment evaluate_periodic()
6+
47
def evaluate_change(self, event, client_factory, configuration_item, valid_rule_parameters):
5-
###############################
6-
# Add your custom logic here. #
7-
###############################
8+
################################################
9+
# Add your custom change-triggered logic here. #
10+
################################################
811

912
return [Evaluation(ComplianceType.NOT_APPLICABLE)]
1013

11-
#def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
12-
# pass
14+
15+
# def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
16+
# ########################################
17+
# # Add your custom periodic logic here. #
18+
# ########################################
19+
# # If you are evaluating resources that are not supported by the Config Service...
20+
# # ...it is often helpful to specify the account as the resource type/ID
21+
# account_id = event['accountId']
22+
# return [
23+
# Evaluation(
24+
# complianceType=ComplianceType.COMPLIANT,
25+
# resourceId=account_id,
26+
# resourceType="AWS::::Account",
27+
# annotation="Use this field to explain why this evaluation occurred.",
28+
# )
29+
# ]
30+
1331

1432
def evaluate_parameters(self, rule_parameters):
1533
valid_rule_parameters = rule_parameters
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from rdklib import Evaluator, Evaluation, ConfigRule, ComplianceType
2+
<%ApplicableResources1%>
3+
class <%RuleName%>(ConfigRule):
4+
# NOTE - you should typically only implement one of evaluate_change() or evaluate_periodic()!
5+
# If implementing a periodic rule, you will need to delete evaluate_change() and uncomment evaluate_periodic()
6+
7+
def evaluate_change(self, event, client_factory, configuration_item, valid_rule_parameters):
8+
################################################
9+
# Add your custom change-triggered logic here. #
10+
################################################
11+
12+
return [Evaluation(ComplianceType.NOT_APPLICABLE)]
13+
14+
15+
# def evaluate_periodic(self, event, client_factory, valid_rule_parameters):
16+
# ########################################
17+
# # Add your custom periodic logic here. #
18+
# ########################################
19+
# # If you are evaluating resources that are not supported by the Config Service...
20+
# # ...it is often helpful to specify the account as the resource type/ID
21+
# account_id = event['accountId']
22+
# return [
23+
# Evaluation(
24+
# complianceType=ComplianceType.COMPLIANT,
25+
# resourceId=account_id,
26+
# resourceType="AWS::::Account",
27+
# annotation="Use this field to explain why this evaluation occurred.",
28+
# )
29+
# ]
30+
31+
32+
def evaluate_parameters(self, rule_parameters):
33+
valid_rule_parameters = rule_parameters
34+
return valid_rule_parameters
35+
36+
37+
################################
38+
# DO NOT MODIFY ANYTHING BELOW #
39+
################################
40+
def lambda_handler(event, context):
41+
my_rule = <%RuleName%>()
42+
evaluator = Evaluator(my_rule<%ApplicableResources2%>)
43+
return evaluator.handle(event, context)

0 commit comments

Comments
 (0)