-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Python - generated template is invalid due to lowercase keys in the schema.
CfnRemediationConfiguration.RemediationParameterValueProperty, CfnRemediationConfiguration.StaticValueProperty and CfnRemediationConfiguration.ResourceValueProperty results in generating invalid cloudFormation template such that the schema keys start with lower-case letters causing failure to validate and deploy the template. resourceValue, staticValue, value and values (keys) start with lowercase in the generated template output.
Reproduction Steps
s3_encryption_rule = ManagedRule(self, "S3BucketServerSideEncryptionEnabled",
identifier="S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED",
config_rule_name="S3BucketServerSideEncryptionEnabled",
input_parameters={})
s3_encryption_rule.scope_to_resource("AWS::S3::Bucket")
automation_assume_role = CfnRemediationConfiguration.RemediationParameterValueProperty(
static_value=CfnRemediationConfiguration.StaticValueProperty(values=["arn:aws:iam::" + Aws.ACCOUNT_ID + ":role/AutoRemediationRole"]))
resource_value = CfnRemediationConfiguration.RemediationParameterValueProperty(
resource_value=CfnRemediationConfiguration.ResourceValueProperty(value="RESOURCE_ID"))
sse_algorithm = CfnRemediationConfiguration.RemediationParameterValueProperty(
static_value=CfnRemediationConfiguration.StaticValueProperty(values=["AES256"]))
remediation = CfnRemediationConfiguration(s3_encryption_rule,
id="AutoRemediationForS3EncryptionRule",
config_rule_name="S3BucketServerSideEncryptionEnabled",
target_id="AWS-EnableS3BucketEncryption",
target_type="SSM_DOCUMENT",
target_version="1",
automatic=True,
maximum_automatic_attempts=5,
retry_attempt_seconds=60,
parameters={"AutomationAssumeRole": automation_assume_role,
"BucketName": resource_value, "SSEAlgorithm": sse_algorithm})Error Log
cdk deploy:
Property validation failure: [Encountered unsupported properties in {/Parameters/AutomationAssumeRole}: [staticValue], Encountered unsupported properties in {/Parameters/BucketName}: [resourceValue], Encountered unsupported properties in {/Parameters/SSEAlgorithm}: [staticValue]]Environment
- CLI Version : 2.0.27
- Framework Version: aws cdk 1.50.0 (build 84acc92)
- Node.js Version: v14.5.0
- OS : Mac OS X Catalina 10.15.5
- Language (Version): Python/3.8.3
Other
The following is getting generated in the CFN template:
"resourceValue": {
"value": "RESOURCE_ID"
}
"staticValue": {
"values": [
"AES256"
]
}resourceValue, staticValue, value and values start with lowercase in the generated template output which is causing the error.
Please note that if I change the mentioned keys in the generated template to: ResourceValue, StaticValue, Value and Values
the validation and deployment works as expected hence the cloud-formation template becomes valid.
The following function works as a workaround in Python (converting the values afterwards which is not ideal obviously:
def normalised_dict(d):
normalised_data = {}
for k, v in d.items():
if isinstance(v, dict):
v = normalised_dict(v)
normalised_data[k[0].upper()+k[1:]] = v
return normalised_dataThis is 🐛 Bug Report