AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
CreatePatchBaseline
与 a 一起使用 CLI
以下代码示例演示如何使用 CreatePatchBaseline
。
- CLI
-
- AWS CLI
-
示例 1:创建具有自动批准功能的补丁基准
以下
create-patch-baseline
示例创建一个 Windows Server 的补丁基准,该基准在 Microsoft 发布补丁 7 天后批准生产环境的补丁。aws ssm create-patch-baseline \ --name
"Windows-Production-Baseline-AutoApproval"
\ --operating-system"WINDOWS"
\ --approval-rules"PatchRules=[{PatchFilterGroup={PatchFilters=[{Key=MSRC_SEVERITY,Values=[Critical,Important,Moderate]},{Key=CLASSIFICATION,Values=[SecurityUpdates,Updates,UpdateRollups,CriticalUpdates]}]},ApproveAfterDays=7}]"
\ --description"Baseline containing all updates approved for Windows Server production systems"
输出:
{ "BaselineId": "pb-045f10b4f3EXAMPLE" }
示例 2:创建带有批准截止日期的补丁基准
以下
create-patch-baseline
示例为 Windows Server 创建补丁基准,其批准 2020 年 7 月 7 日或之前在生产环境中发布的所有补丁。aws ssm create-patch-baseline \ --name
"Windows-Production-Baseline-AutoApproval"
\ --operating-system"WINDOWS"
\ --approval-rules"PatchRules=[{PatchFilterGroup={PatchFilters=[{Key=MSRC_SEVERITY,Values=[Critical,Important,Moderate]},{Key=CLASSIFICATION,Values=[SecurityUpdates,Updates,UpdateRollups,CriticalUpdates]}]},ApproveUntilDate=2020-07-07}]"
\ --description"Baseline containing all updates approved for Windows Server production systems"
输出:
{ "BaselineId": "pb-045f10b4f3EXAMPLE" }
示例 3:使用存储在JSON文件中的批准规则创建补丁基准
以下
create-patch-baseline
示例为 Amazon Linux 2017.09 创建补丁基准,其将在补丁发布 7 天后批准生产环境的补丁,指定补丁基准的批准规则,并指定补丁的自定义存储库。aws ssm create-patch-baseline \ --cli-input-json
file://my-amazon-linux-approval-rules-and-repo.json
my-amazon-linux-approval-rules-and-repo.json
的内容:{ "Name": "Amazon-Linux-2017.09-Production-Baseline", "Description": "My approval rules patch baseline for Amazon Linux 2017.09 instances", "OperatingSystem": "AMAZON_LINUX", "Tags": [ { "Key": "Environment", "Value": "Production" } ], "ApprovalRules": { "PatchRules": [ { "ApproveAfterDays": 7, "EnableNonSecurity": true, "PatchFilterGroup": { "PatchFilters": [ { "Key": "SEVERITY", "Values": [ "Important", "Critical" ] }, { "Key": "CLASSIFICATION", "Values": [ "Security", "Bugfix" ] }, { "Key": "PRODUCT", "Values": [ "AmazonLinux2017.09" ] } ] } } ] }, "Sources": [ { "Name": "My-AL2017.09", "Products": [ "AmazonLinux2017.09" ], "Configuration": "[amzn-main] \nname=amzn-main-Base\nmirrorlist=http://repo./$awsregion./$awsdomain//$releasever/main/mirror.list //nmirrorlist_expire=300//nmetadata_expire=300 \npriority=10 \nfailovermethod=priority \nfastestmirror_enabled=0 \ngpgcheck=1 \ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-ga \nenabled=1 \nretries=3 \ntimeout=5\nreport_instanceid=yes" } ] }
示例 4:创建指定已批准和已拒绝补丁的补丁基准
以下
create-patch-baseline
示例明确指定要批准和拒绝的补丁,作为默认批准规则的例外情况。aws ssm create-patch-baseline \ --name
"Amazon-Linux-2017.09-Alpha-Baseline"
\ --description"My custom approve/reject patch baseline for Amazon Linux 2017.09 instances"
\ --operating-system"AMAZON_LINUX"
\ --approved-patches"CVE-2018-1234567,example-pkg-EE-2018*.amzn1.noarch"
\ --approved-patches-compliance-level"HIGH"
\ --approved-patches-enable-non-security \ --tags"Key=Environment,Value=Alpha"
有关更多信息,请参阅《AWS Systems Manager 用户指南》中的创建自定义补丁基准。
-
有关API详细信息,请参阅 “CreatePatchBaseline AWS CLI
命令参考”。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例创建补丁基准,用于在 Microsoft 发布补丁 7 天后为在生产环境中运行 Windows Server 2019 的托管式实例批准补丁。
$rule = New-Object Amazon.SimpleSystemsManagement.Model.PatchRule $rule.ApproveAfterDays = 7 $ruleFilters = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilterGroup $patchFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter $patchFilter.Key="PRODUCT" $patchFilter.Values="WindowsServer2019" $severityFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter $severityFilter.Key="MSRC_SEVERITY" $severityFilter.Values.Add("Critical") $severityFilter.Values.Add("Important") $severityFilter.Values.Add("Moderate") $classificationFilter = New-Object Amazon.SimpleSystemsManagement.Model.PatchFilter $classificationFilter.Key = "CLASSIFICATION" $classificationFilter.Values.Add( "SecurityUpdates" ) $classificationFilter.Values.Add( "Updates" ) $classificationFilter.Values.Add( "UpdateRollups" ) $classificationFilter.Values.Add( "CriticalUpdates" ) $ruleFilters.PatchFilters.Add($severityFilter) $ruleFilters.PatchFilters.Add($classificationFilter) $ruleFilters.PatchFilters.Add($patchFilter) $rule.PatchFilterGroup = $ruleFilters New-SSMPatchBaseline -Name "Production-Baseline-Windows2019" -Description "Baseline containing all updates approved for production systems" -ApprovalRules_PatchRule $rule
输出:
pb-0z4z6221c4296b23z
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考CreatePatchBaseline中的。
-