Reputation: 137
I am using AWS CDK, library @aws-cdk/aws-ssm and TypeScript to create PatchBaseline. I can create Patch baseline but I am not able to define any approvalRules. I have found similar thread where Alex Nelson creates approvalRules as an object using RuleProperty, he does it in Python but I am not able to replicate this procedure in TypeScript. For some reason I cannot use RuleProperty in TypeScript like Alex did in Python, more in this post.
This line of code gives me an error that Property 'RuleProperty' does not exist on type 'typeof CfnPatchBaseline'.
const patch_baseline_rule = new ssm.CfnPatchBaseline.RuleProperty();
I spent hours going through the CDK documentation but I did not find there anything usefull related to my issue. In case of RuleGroupProperty the documentation does not provide any examples at all.
My question is, how to type following code (Python) in TypeScript?
patch_baseline_rule = ssm.CfnPatchBaseline.RuleProperty(approve_after_days=0,
compliance_level='CRITICAL',
enable_non_security=True,
patch_filter_group=patch_baseline_patch_filter_group
)
patch_baseline_rule_group = ssm.CfnPatchBaseline.RuleGroupProperty(patch_rules=[patch_baseline_rule])
patch_baseline = ssm.CfnPatchBaseline(self, 'rPatchBaseline',
name=f'TestPatchBaseline_Linux',
description='TestPatchBaseline for Linux updates, Amazon_Linux_2 distr.',
operating_system='AMAZON_LINUX_2',
approved_patches_enable_non_security=True,
patch_groups=['AWS-Linux-2-Test'],
approval_rules=patch_baseline_rule_group,
)
Upvotes: 1
Views: 546
Reputation:
Things like RuleProperty
and RuleGroupProperty
are classes in Python, but in TypeScript, they're just interfaces, so you don't directly create them. Instead, you create normal JavaScript objects, and your editor or the CDK itself will tell you if you're creating the object incorrectly.
In case you're not aware, it's also common practice to use camelCase
names in JavaScript, rather than snake_case
like you'd do in Python. Because of that, you'll need to specify property names as camelCase
as well.
Note: the this
keyword is used in JavaScript/TypeScript, while it's self
in Python.
Here is the TypeScript equivalent of your Python code:
import ssm from "@aws-cdk/aws-ssm";
const patchBaselineRule = {
approveAfterDays: 0,
complianceLevel: "CRITICAL",
enableNonSecurity: true,
patchFilterGroup: patch_baseline_patch_filter_group,
};
const patchBaselineRuleGroup = {
patchRules: [patchBaselineRule],
};
const patchBaseline = new ssm.CfnPatchBaseline(this, "rPatchBaseline", {
name: "TestPatchBaseline_Linux",
description: "TestPatchBaseline for Linux updates, Amazon_Linux_2 distr.",
operatingSystem: "AMAZON_LINUX_2",
approvedPatchesEnableNonSecurity: true,
patchGroups: ["AWS-Linux-2-Test"],
approvalRules: patchBaselineRuleGroup,
});
Upvotes: 0