Skip to content

Commit

Permalink
add python 3.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorrissirromb committed Apr 29, 2024
1 parent 575cef4 commit 90e490b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ rule and populate it with several files, including a skeleton of your
Lambda code.

```bash
rdk create MyRule --runtime python3.11 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
rdk create MyRule --runtime python3.12 --resource-types AWS::EC2::Instance --input-parameters '{"desiredInstanceType":"t2.micro"}'
Running create!
Local Rule files created.
```
Expand Down Expand Up @@ -222,7 +222,7 @@ will overwrite existing values, any that you do not specify will not be
changed.
```bash
rdk modify MyRule --runtime python3.11 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
rdk modify MyRule --runtime python3.12 --maximum-frequency TwentyFour_Hours --input-parameters '{"desiredInstanceType":"t2.micro"}'
Running modify!
Modified Rule 'MyRule'. Use the `deploy` command to push your changes to AWS.
```
Expand Down Expand Up @@ -396,7 +396,7 @@ by rdk. To disable the supported resource check use the optional flag
'--skip-supported-resource-check' during the create command.
```bash
rdk create MyRule --runtime python3.11 --resource-types AWS::New::ResourceType --skip-supported-resource-check
rdk create MyRule --runtime python3.12 --resource-types AWS::New::ResourceType --skip-supported-resource-check
'AWS::New::ResourceType' not found in list of accepted resource types.
Skip-Supported-Resource-Check Flag set (--skip-supported-resource-check), ignoring missing resource type error.
Running create!
Expand All @@ -415,7 +415,7 @@ performing `rdk create`. This opens up new features like :
2. Custom lambda function naming as per personal or enterprise standards.
```bash
rdk create MyLongerRuleName --runtime python3.11 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
rdk create MyLongerRuleName --runtime python3.12 --resource-types AWS::EC2::Instance --custom-lambda-name custom-prefix-for-MyLongerRuleName
Running create!
Local Rule files created.
```
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
include = [
"README.md",
Expand All @@ -52,6 +53,8 @@ include = [
"rdk/template/runtime/python3.10-lib/*",
"rdk/template/runtime/python3.11/*",
"rdk/template/runtime/python3.11-lib/*",
"rdk/template/runtime/python3.12/*",
"rdk/template/runtime/python3.12-lib/*",
"rdk/template/runtime/dotnetcore1.0/*",
"rdk/template/runtime/dotnetcore1.0/bin/*",
"rdk/template/runtime/dotnetcore1.0/obj/*",
Expand Down
38 changes: 27 additions & 11 deletions rdk/rdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def get_rule_parser(is_required, command):
"python3.10-lib",
"python3.11",
"python3.11-lib",
"python3.12",
"python3.12-lib",
],
metavar="",
)
Expand All @@ -287,7 +289,7 @@ def get_rule_parser(is_required, command):
required=False,
help="[optional] Provide custom lambda name",
)
parser.set_defaults(runtime="python3.11-lib")
parser.set_defaults(runtime="python3.12-lib")
parser.add_argument(
"-r",
"--resource-types",
Expand Down Expand Up @@ -1228,6 +1230,8 @@ def create(self):
"python3.10-lib": ".py",
"python3.11": ".py",
"python3.11-lib": ".py",
"python3.12": ".py",
"python3.12-lib": ".py",
}
if self.args.runtime not in extension_mapping:
print("rdk does not support that runtime yet.")
Expand Down Expand Up @@ -1272,6 +1276,7 @@ def create(self):
"python3.9-lib",
"python3.10-lib",
"python3.11-lib",
"python3.12-lib",
]:
if self.args.resource_types:
applicable_resource_list = ""
Expand Down Expand Up @@ -2220,9 +2225,7 @@ def deploy_organization(self):
excluded_via_rule_params = rule_params.get("ExcludedAccounts").split(",")
else:
excluded_via_rule_params = []
combined_excluded_accounts_set = set(
excluded_via_rule_params + self.args.excluded_accounts
)
combined_excluded_accounts_set = set(excluded_via_rule_params + self.args.excluded_accounts)
combined_excluded_accounts_str = ",".join(combined_excluded_accounts_set)
else:
combined_excluded_accounts_str = ""
Expand Down Expand Up @@ -2645,6 +2648,8 @@ def test_local(self):
"python3.10-lib",
"python3.11",
"python3.11-lib",
"python3.12",
"python3.12-lib",
):
print("Skipping " + rule_name + " - Runtime not supported for local testing.")
continue
Expand Down Expand Up @@ -2847,9 +2852,9 @@ def create_rule_template(self):
# First add the common elements - description, parameters, and resource section header
template = {}
template["AWSTemplateFormatVersion"] = "2010-09-09"
template[
"Description"
] = "AWS CloudFormation template to create custom AWS Config rules. You will be billed for the AWS resources used if you create a stack from this template."
template["Description"] = (
"AWS CloudFormation template to create custom AWS Config rules. You will be billed for the AWS resources used if you create a stack from this template."
)

optional_parameter_group = {"Label": {"default": "Optional"}, "Parameters": []}

Expand Down Expand Up @@ -3870,6 +3875,8 @@ def __get_handler(self, rule_name, params):
"python3.10-lib",
"python3.11",
"python3.11-lib",
"python3.12",
"python3.12-lib",
]:
return rule_name + ".lambda_handler"
elif params["SourceRuntime"] in ["java8"]:
Expand All @@ -3882,6 +3889,7 @@ def __get_runtime_string(self, params):
"python3.9-lib",
"python3.10-lib",
"python3.11-lib",
"python3.12-lib",
]:
runtime = params["SourceRuntime"].split("-")
return runtime[0]
Expand Down Expand Up @@ -4100,9 +4108,9 @@ def __create_function_cloudformation_template(self):
# First add the common elements - description, parameters, and resource section header
template = {}
template["AWSTemplateFormatVersion"] = "2010-09-09"
template[
"Description"
] = "AWS CloudFormation template to create Lambda functions for backing custom AWS Config rules. You will be billed for the AWS resources used if you create a stack from this template."
template["Description"] = (
"AWS CloudFormation template to create Lambda functions for backing custom AWS Config rules. You will be billed for the AWS resources used if you create a stack from this template."
)

parameters = {}
parameters["SourceBucket"] = {}
Expand Down Expand Up @@ -4275,6 +4283,7 @@ def __get_lambda_layers(self, my_session, args, params):
"python3.9-lib",
"python3.10-lib",
"python3.11-lib",
"python3.12-lib",
]:
if hasattr(args, "generated_lambda_layer") and args.generated_lambda_layer:
lambda_layer_version = self.__get_existing_lambda_layer(
Expand Down Expand Up @@ -4401,7 +4410,14 @@ def __create_new_lambda_layer_locally(self, my_session, layer_name="rdklib-layer
lambda_client.publish_layer_version(
LayerName=layer_name,
Content={"S3Bucket": bucket_name, "S3Key": layer_name},
CompatibleRuntimes=["python3.7", "python3.8", "python3.9", "python3.10", "python3.11"],
CompatibleRuntimes=[
"python3.7",
"python3.8",
"python3.9",
"python3.10",
"python3.11",
"python3.12",
],
)

print(f"[{region}]: Deleting temporary S3 Bucket")
Expand Down
22 changes: 15 additions & 7 deletions testing/linux-python3-buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@ phases:
commands:
- rdk create-region-set -o test-region
- rdk -f test-region.yaml init
- rdk create MFA_ENABLED_RULE --runtime python3.11 --resource-types AWS::IAM::User
- rdk create MFA_ENABLED_RULE --runtime python3.12 --resource-types AWS::IAM::User
- rdk -f test-region.yaml deploy MFA_ENABLED_RULE
- sleep 30
- python3 testing/multi_region_execution_test.py
- sleep 30
- rdk -f test-region.yaml undeploy --force MFA_ENABLED_RULE
- python3 testing/partition_test.py
- rdk init --generate-lambda-layer
- rdk create LP3_TestRule_P312_lib --runtime python3.12-lib --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P311_lib --runtime python3.11-lib --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P310_lib --runtime python3.10-lib --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P39_lib --runtime python3.9-lib --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P38_lib --runtime python3.8-lib --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P37_lib --runtime python3.7-lib --resource-types AWS::EC2::SecurityGroup
- rdk -f test-region.yaml deploy LP3_TestRule_P312_lib --generated-lambda-layer
- rdk -f test-region.yaml deploy LP3_TestRule_P311_lib --generated-lambda-layer
- rdk -f test-region.yaml deploy LP3_TestRule_P310_lib --generated-lambda-layer
- rdk -f test-region.yaml deploy LP3_TestRule_P39_lib --generated-lambda-layer
- rdk -f test-region.yaml deploy LP3_TestRule_P38_lib --generated-lambda-layer
- rdk -f test-region.yaml deploy LP3_TestRule_P37_lib --generated-lambda-layer
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P312_lib
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P311_lib
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P310_lib
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P39_lib
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P38_lib
- yes | rdk -f test-region.yaml undeploy LP3_TestRule_P37_lib
- rdk create LP3_TestRule_P312 --runtime python3.12 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P311 --runtime python3.11 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P310 --runtime python3.10 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P39 --runtime python3.9 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P38 --runtime python3.8 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P37 --runtime python3.7 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_P3 --runtime python3.11 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_EFSFS --runtime python3.11 --resource-types AWS::EFS::FileSystem
- rdk create LP3_TestRule_ECSTD --runtime python3.11 --resource-types AWS::ECS::TaskDefinition
- rdk create LP3_TestRule_ECSS --runtime python3.11 --resource-types AWS::ECS::Service
- rdk create LP3_TestRule_P3 --runtime python3.12 --resource-types AWS::EC2::SecurityGroup
- rdk create LP3_TestRule_EFSFS --runtime python3.12 --resource-types AWS::EFS::FileSystem
- rdk create LP3_TestRule_ECSTD --runtime python3.12 --resource-types AWS::ECS::TaskDefinition
- rdk create LP3_TestRule_ECSS --runtime python3.12 --resource-types AWS::ECS::Service
- rdk modify LP3_TestRule_P3 --input-parameters '{"TestParameter":"TestValue"}'
- rdk create LP3_TestRule_P37_Periodic --runtime python3.7 --maximum-frequency One_Hour
- rdk create LP3_TestRule_P37lib_Periodic --runtime python3.7-lib --maximum-frequency One_Hour
Expand All @@ -55,7 +61,8 @@ phases:
- rdk create LP3_TestRule_P310lib_Periodic --runtime python3.10-lib --maximum-frequency One_Hour
- rdk create LP3_TestRule_P311_Periodic --runtime python3.11 --maximum-frequency One_Hour
- rdk create LP3_TestRule_P311lib_Periodic --runtime python3.11-lib --maximum-frequency One_Hour
- rdk test-local --all
- rdk create LP3_TestRule_P312_Periodic --runtime python3.12 --maximum-frequency One_Hour
- rdk create LP3_TestRule_P312lib_Periodic --runtime python3.12-lib --maximum-frequency One_Hour - rdk test-local --all
- rdk deploy --all
- yes | rdk undeploy LP3_TestRule_P3
- yes | rdk undeploy LP3_TestRule_P37
Expand All @@ -68,7 +75,8 @@ phases:
- yes | rdk undeploy LP3_TestRule_P310_Periodic
- yes | rdk undeploy LP3_TestRule_P311
- yes | rdk undeploy LP3_TestRule_P311_Periodic
- sleep 30
- yes | rdk undeploy LP3_TestRule_P312
- yes | rdk undeploy LP3_TestRule_P312_Periodic - sleep 30
- rdk logs LP3_TestRule_P3
- yes | rdk undeploy -a
post_build:
Expand Down
20 changes: 13 additions & 7 deletions testing/windows-python3-buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ phases:
commands:
- rdk create-region-set -o test-region
- rdk -f test-region.yaml init
- rdk create W_MFA_ENABLED_RULE --runtime python3.11 --resource-types AWS::IAM::User
- rdk create W_MFA_ENABLED_RULE --runtime python3.12 --resource-types AWS::IAM::User
- rdk -f test-region.yaml deploy W_MFA_ENABLED_RULE
- python testing/win_multi_region_execution_test.py
- rdk -f test-region.yaml undeploy --force W_MFA_ENABLED_RULE
- python testing/win_partition_test.py
- rdk init --generate-lambda-layer
- rdk create WP3_TestRule_P312_lib --runtime python3.12-lib --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P311_lib --runtime python3.11-lib --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P310_lib --runtime python3.10-lib --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P39_lib --runtime python3.9-lib --resource-types AWS::EC2::SecurityGroup
Expand All @@ -33,16 +34,17 @@ phases:
- rdk -f test-region.yaml undeploy WP3_TestRule_P39_lib --force
- rdk -f test-region.yaml undeploy WP3_TestRule_P38_lib --force
- rdk -f test-region.yaml undeploy WP3_TestRule_P37_lib --force
- rdk create WP3_TestRule_P312 --runtime python3.12 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P311 --runtime python3.11 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P310 --runtime python3.10 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P39 --runtime python3.9 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P38 --runtime python3.8 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P37 --runtime python3.7 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_P3 --runtime python3.11 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_EFSFS --runtime python3.11 --resource-types AWS::EFS::FileSystem
- rdk create WP3_TestRule_ECSTD --runtime python3.11 --resource-types AWS::ECS::TaskDefinition
- rdk create WP3_TestRule_ECSS --runtime python3.11 --resource-types AWS::ECS::Service
- rdk modify WP3_TestRule_P3 --runtime python3.11
- rdk create WP3_TestRule_P3 --runtime python3.12 --resource-types AWS::EC2::SecurityGroup
- rdk create WP3_TestRule_EFSFS --runtime python3.12 --resource-types AWS::EFS::FileSystem
- rdk create WP3_TestRule_ECSTD --runtime python3.12 --resource-types AWS::ECS::TaskDefinition
- rdk create WP3_TestRule_ECSS --runtime python3.12 --resource-types AWS::ECS::Service
- rdk modify WP3_TestRule_P3 --runtime python3.12
- rdk create WP3_TestRule_P37_Periodic --runtime python3.7 --maximum-frequency One_Hour
- rdk create WP3_TestRule_P37lib_Periodic --runtime python3.7-lib --maximum-frequency One_Hour
- rdk create WP3_TestRule_P38_Periodic --runtime python3.8 --maximum-frequency One_Hour
Expand All @@ -53,6 +55,8 @@ phases:
- rdk create WP3_TestRule_P310lib_Periodic --runtime python3.10-lib --maximum-frequency One_Hour
- rdk create WP3_TestRule_P311_Periodic --runtime python3.11 --maximum-frequency One_Hour
- rdk create WP3_TestRule_P311lib_Periodic --runtime python3.11-lib --maximum-frequency One_Hour
- rdk create WP3_TestRule_P312_Periodic --runtime python3.12 --maximum-frequency One_Hour
- rdk create WP3_TestRule_P312lib_Periodic --runtime python3.12-lib --maximum-frequency One_Hour
- rdk test-local --all
- rdk deploy --all
- rdk undeploy WP3_TestRule_P3 --force
Expand All @@ -65,7 +69,9 @@ phases:
- rdk undeploy WP3_TestRule_P310 --force
- rdk undeploy WP3_TestRule_P310_Periodic --force
- rdk undeploy WP3_TestRule_P311 --force
- rdk undeploy WP3_TestRule_P311_Periodic --force
- rdk undeploy WP3_TestRule_P311_Periodic --force
- rdk undeploy WP3_TestRule_P312 --force
- rdk undeploy WP3_TestRule_P312_Periodic --force
- rdk logs WP3_TestRule_P3
- rdk undeploy -a --force
post_build:
Expand Down

0 comments on commit 90e490b

Please sign in to comment.