使用 Shield 示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Shield 示例 Amazon CLI

以下代码示例向您展示了如何使用 with Shield 来执行操作和实现常见场景。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 associate-drt-log-bucket

Amazon CLI

授权 DRT 访问亚马逊 S3 存储桶

以下associate-drt-log-bucket示例在 DRT 和指定的 S3 存储桶之间创建关联。这允许 DRT 代表账户访问存储桶。 :

aws shield associate-drt-log-bucket \ --log-bucket flow-logs-for-website-lb

此命令不生成任何输出。

有关更多信息,请参阅Amazon Shield 高级开发者指南》中的授权 DDoS 响应团队

以下代码示例演示如何使用 associate-drt-role

Amazon CLI

授权 DRT 代表您缓解潜在的攻击

以下associate-drt-role示例在 DRT 和指定角色之间创建关联。DRT 可以使用该角色来访问和管理账户。

aws shield associate-drt-role \ --role-arn arn:aws:iam::123456789012:role/service-role/DrtRole

此命令不生成任何输出。

有关更多信息,请参阅Amazon Shield 高级开发者指南》中的授权 DDoS 响应团队

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考AssociateDrtRole中的。

以下代码示例演示如何使用 create-protection

Amazon CLI

为单个 Amazon 资源启用 Amazon Shield 高级保护

以下create-protection示例为指定 Amazon CloudFront 发行版启用 Shield 高级保护。

aws shield create-protection \ --name "Protection for CloudFront distribution" \ --resource-arn arn:aws:cloudfront::123456789012:distribution/E198WC25FXOWY8

输出:

{ "ProtectionId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的 “指定要保护的资源”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateProtection中的。

以下代码示例演示如何使用 create-subscription

Amazon CLI

为账户启用 Amazon Shield 高级防护

以下create-subscription示例为账户启用 Shield 高级保护。

aws shield create-subscription

此命令不生成任何输出。

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的Amazon Shield 高级版入门

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateSubscription中的。

以下代码示例演示如何使用 delete-protection

Amazon CLI

从 Amazon 资源中移除 Amazon Shield 高级防护

以下delete-protection示例移除了指定的 Amazon Shield 高级保护。

aws shield delete-protection \ --protection-id a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

此命令不生成任何输出。

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的从 Amazon 资源中移除Amazon Shield Advance d。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteProtection中的。

以下代码示例演示如何使用 describe-attack

Amazon CLI

检索攻击的详细描述

以下describe-attack示例显示有关具有指定攻击 ID 的 DDoS 攻击的详细信息。您可以通过运行list-attacks命令来获取攻击 ID。

aws shield describe-attack --attack-id a1b2c3d4-5678-90ab-cdef-EXAMPLE22222

输出:

{ "Attack": { "AttackId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "ResourceArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/testElb", "SubResources": [ { "Type": "IP", "Id": "192.0.2.2", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 11786208.0, "N": 12, "Unit": "BPS" } ] } ], "Counters": [] }, { "Type": "IP", "Id": "192.0.2.3", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 9821840.0, "N": 10, "Unit": "BPS" } ] } ], "Counters": [] }, { "Type": "IP", "Id": "192.0.2.4", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 7857472.0, "N": 8, "Unit": "BPS" } ] } ], "Counters": [] }, { "Type": "IP", "Id": "192.0.2.5", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 1964368.0, "N": 2, "Unit": "BPS" } ] } ], "Counters": [] }, { "Type": "IP", "Id": "2001:DB8::bcde:4321:8765:0:0", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 1964368.0, "N": 2, "Unit": "BPS" } ] } ], "Counters": [] }, { "Type": "IP", "Id": "192.0.2.6", "AttackVectors": [ { "VectorType": "SYN_FLOOD", "VectorCounters": [ { "Name": "SYN_FLOOD_BPS", "Max": 982184.0, "Average": 982184.0, "Sum": 1964368.0, "N": 2, "Unit": "BPS" } ] } ], "Counters": [] } ], "StartTime": 1576024927.457, "EndTime": 1576025647.457, "AttackCounters": [], "AttackProperties": [ { "AttackLayer": "NETWORK", "AttackPropertyIdentifier": "SOURCE_IP_ADDRESS", "TopContributors": [ { "Name": "198.51.100.5", "Value": 2024475682 }, { "Name": "198.51.100.8", "Value": 1311380863 }, { "Name": "203.0.113.4", "Value": 900599855 }, { "Name": "198.51.100.4", "Value": 769417366 }, { "Name": "203.1.113.13", "Value": 757992847 } ], "Unit": "BYTES", "Total": 92773354841 }, { "AttackLayer": "NETWORK", "AttackPropertyIdentifier": "SOURCE_COUNTRY", "TopContributors": [ { "Name": "United States", "Value": 80938161764 }, { "Name": "Brazil", "Value": 9929864330 }, { "Name": "Netherlands", "Value": 1635009446 }, { "Name": "Mexico", "Value": 144832971 }, { "Name": "Japan", "Value": 45369000 } ], "Unit": "BYTES", "Total": 92773354841 }, { "AttackLayer": "NETWORK", "AttackPropertyIdentifier": "SOURCE_ASN", "TopContributors": [ { "Name": "12345", "Value": 74953625841 }, { "Name": "12346", "Value": 4440087595 }, { "Name": "12347", "Value": 1635009446 }, { "Name": "12348", "Value": 1221230000 }, { "Name": "12349", "Value": 1199425294 } ], "Unit": "BYTES", "Total": 92755479921 } ], "Mitigations": [] } }

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的查看 DDoS 事件

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeAttack中的。

以下代码示例演示如何使用 describe-drt-access

Amazon CLI

要检索 DRT 必须代表您缓解攻击的授权的描述

以下describe-drt-access示例检索 DRT 拥有的角色和 S3 存储桶授权,这使其能够代表您响应潜在的攻击。

aws shield describe-drt-access

输出:

{ "RoleArn": "arn:aws:iam::123456789012:role/service-role/DrtRole", "LogBucketList": [ "flow-logs-for-website-lb" ] }

有关更多信息,请参阅Amazon Shield 高级开发者指南》中的授权 DDoS 响应团队

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeDrtAccess中的。

以下代码示例演示如何使用 describe-emergency-contact-settings

Amazon CLI

检索您在 DRT 中存档的紧急电子邮件地址

以下describe-emergency-contact-settings示例检索账户的 DRT 中存档的电子邮件地址。这些是 DRT 在应对可疑攻击时应联系的地址。

aws shield describe-emergency-contact-settings

输出:

{ "EmergencyContactList": [ { "EmailAddress": "ops@example.com" }, { "EmailAddress": "ddos-notifications@example.com" } ] }

有关更多信息,请参阅《 Amazon Shield< https://docs.aws.amazon.com/waf/latest/developerguide/ddos-overview.html > 高级开发者指南》中的Amazon Shield 工作原理。

以下代码示例演示如何使用 describe-protection

Amazon CLI

检索 Amazon Shield 高级防护的详细信息

以下describe-protection示例显示有关具有指定 ID 的 Shield 高级防护的详细信息。您可以通过运行list-protections命令来获取保护 ID。

aws shield describe-protection \ --protection-id a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "Protection": { "Id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "Name": "1.2.3.4", "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:eip-allocation/eipalloc-0ac1537af40742a6d" } }

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的 “指定要保护的资源”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeProtection中的。

以下代码示例演示如何使用 describe-subscription

Amazon CLI

检索账户的 Amazon Shield 高级保护详情

以下describe-subscription示例显示了有关为该账户提供的 Shield 高级保护的详细信息。 :

aws shield describe-subscription

输出:

{ "Subscription": { "StartTime": 1534368978.0, "EndTime": 1597613778.0, "TimeCommitmentInSeconds": 63244800, "AutoRenew": "ENABLED", "Limits": [ { "Type": "GLOBAL_ACCELERATOR", "Max": 1000 }, { "Type": "ROUTE53_HOSTED_ZONE", "Max": 1000 }, { "Type": "CF_DISTRIBUTION", "Max": 1000 }, { "Type": "ELB_LOAD_BALANCER", "Max": 1000 }, { "Type": "EC2_ELASTIC_IP_ALLOCATION", "Max": 1000 } ] } }

有关更多信息,请参阅《 Amazon Shield 高级开发者指南》中的Amazon Shield 工作原理

以下代码示例演示如何使用 disassociate-drt-log-bucket

Amazon CLI

移除 DRT 代表您访问 Amazon S3 存储桶的授权

以下disassociate-drt-log-bucket示例删除了 DRT 与指定 S3 存储桶之间的关联。此命令完成后,DRT 将无法再代表该账户访问存储桶。

aws shield disassociate-drt-log-bucket \ --log-bucket flow-logs-for-website-lb

此命令不生成任何输出。

有关更多信息,请参阅Amazon Shield 高级开发者指南》中的授权 DDoS 响应团队

以下代码示例演示如何使用 disassociate-drt-role

Amazon CLI

移除 DRT 的授权以代表您缓解潜在攻击

以下disassociate-drt-role示例删除了 DRT 与账户之间的关联。通话结束后,DRT 将无法再访问或管理您的帐户。

aws shield disassociate-drt-role

此命令不生成任何输出。

有关更多信息,请参阅Amazon Shield 高级开发者指南》中的授权 DDoS 响应团队

以下代码示例演示如何使用 get-subscription-state

Amazon CLI

检索账户 Amazon Shield Advanced 订阅的当前状态

以下get-subscription-state示例检索账户的 Shield 高级保护的状态。

aws shield get-subscription-state

输出:

{ "SubscriptionState": "ACTIVE" }

有关更多信息,请参阅《 Amazon Shield 高级开发者指南》中的Amazon Shield 工作原理

以下代码示例演示如何使用 list-attacks

Amazon CLI

从 Amazon Shield Advanced 中检索攻击摘要

以下list-attacks示例检索指定 Amazon CloudFront 分布在指定时间段内的攻击摘要。响应包括攻击 ID,您可以将其提供给describe-attack命令以获取有关攻击的详细信息。

aws shield list-attacks \ --resource-arns arn:aws:cloudfront::12345678910:distribution/E1PXMP22ZVFAOR \ --start-time FromInclusive=1529280000,ToExclusive=1529300000

输出:

{ "AttackSummaries": [ { "AttackId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "ResourceArn": "arn:aws:cloudfront::123456789012:distribution/E1PXMP22ZVFAOR", "StartTime": 1529280000.0, "EndTime": 1529449200.0, "AttackVectors": [ { "VectorType": "SYN_FLOOD" } ] } ] }

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的查看 DDoS 事件

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListAttacks中的。

以下代码示例演示如何使用 list-protections

Amazon CLI

从 Shi Amazon eld Advanced 中检索防护摘要

以下list-protections示例检索为该账户启用的保护的摘要。

aws shield list-protections

输出:

{ "Protections": [ { "Id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "Name": "Protection for CloudFront distribution", "ResourceArn": "arn:aws:cloudfront::123456789012:distribution/E198WC25FXOWY8" } ] }

有关更多信息,请参阅《Amazon Shield 高级开发者指南》中的 “指定要保护的资源”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListProtections中的。

以下代码示例演示如何使用 update-emergency-contact-settings

Amazon CLI

定义 DRT 中存档的紧急电子邮件地址

以下update-emergency-contact-settings示例定义了 DRT 在响应可疑攻击时应联系的两个电子邮件地址。

aws shield update-emergency-contact-settings \ --emergency-contact-list EmailAddress=ops@example.com EmailAddress=ddos-notifications@example.com

此命令不生成任何输出。

有关更多信息,请参阅《 Amazon Shield 高级开发者指南》中的Amazon Shield 工作原理

以下代码示例演示如何使用 update-subscription

Amazon CLI

修改账户的 Amazon Shield Advanced 订阅

以下update-subscription示例为该账户启用了 Amazon Shield Advanced 订阅的自动续订。

aws shield update-subscription \ --auto-renew ENABLED

此命令不生成任何输出。

有关更多信息,请参阅《 Amazon Shield 高级开发者指南》中的Amazon Shield 工作原理

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateSubscription中的。