简体   繁体   中英

AWS CDK PatchBaseline - TypeScript

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,
                                      )

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,
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM