本文档仅适用于 Amazon CLI 版本 1。有关 Amazon CLI 版本 2 的相关文档,请参阅版本 2 用户指南。
使用 Amazon CLI 的 Shield 示例
以下代码示例演示了如何通过将 Amazon Command Line Interface与 Shield 结合使用,来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 associate-drt-log-bucket。
- Amazon CLI
- 
             
                    授权 DRT 访问 Amazon S3 存储桶 以下 associate-drt-log-bucket示例在 DRT 和指定的 S3 存储桶之间创建关联。这允许 DRT 代表账户访问存储桶:aws shield associate-drt-log-bucket \ --log-bucketflow-logs-for-website-lb此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的授权 DDoS 响应团队。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 AssociateDrtLogBucket 。 
 
- 
                    
以下代码示例演示了如何使用 associate-drt-role。
- Amazon CLI
- 
             
                    授权 DRT 代表您缓解潜在攻击 以下 associate-drt-role示例在 DRT 和指定角色之间创建关联。DRT 可以使用该角色访问和管理账户。aws shield associate-drt-role \ --role-arnarn:aws:iam::123456789012:role/service-role/DrtRole此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的授权 DDoS 响应团队。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 AssociateDrtRole 。 
 
- 
                    
以下代码示例演示了如何使用 create-protection。
- Amazon CLI
- 
             
                    为单个 Amazon 资源启用 Amazon Shield Advanced 保护 以下 create-protection示例为指定 Amazon CloudFront 分配启用 Shield Advanced 保护。aws shield create-protection \ --name"Protection for CloudFront distribution"\ --resource-arnarn:aws:cloudfront::123456789012:distribution/E198WC25FXOWY8输出: { "ProtectionId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的指定要保护的资源。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateProtection 。 
 
- 
                    
以下代码示例演示了如何使用 create-subscription。
- Amazon CLI
- 
             
                    为账户启用 Amazon Shield Advanced 保护 以下 create-subscription示例为账户启用 Shield Advanced 保护。aws shield create-subscription此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的 Amazon Shield Advanced 入门。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateSubscription 。 
 
- 
                    
以下代码示例演示了如何使用 delete-protection。
- Amazon CLI
- 
             
                    从 Amazon 资源中移除 Amazon Shield Advanced 保护 以下 delete-protection示例移除指定的 Amazon Shield Advanced 保护。aws shield delete-protection \ --protection-ida1b2c3d4-5678-90ab-cdef-EXAMPLE11111此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的从 Amazon 资源中移除 Amazon Shield Advanced。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteProtection 。 
 
- 
                    
以下代码示例演示了如何使用 describe-attack。
- Amazon CLI
- 
             
                    检索攻击的详细描述 以下 describe-attack示例显示指定攻击 ID 的 DDoS 攻击的详细信息。您可以通过运行list-attacks命令来获取攻击 ID。aws shield describe-attack --attack-ida1b2c3d4-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 Advanced 开发人员指南》中的查看 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 Advanced 开发人员指南》中的授权 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 Advanced 开发人员指南》中的“Amazon Shield 工作原理<https://docs.aws.amazon.com/waf/latest/developerguide/ddos-overview.html>”。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeEmergencyContactSettings 。 
 
- 
                    
以下代码示例演示了如何使用 describe-protection。
- Amazon CLI
- 
             
                    检索 Amazon Shield Advanced 保护的详细信息 以下 describe-protection示例显示指定 ID 的 Shield Advanced 保护的详细信息。您可以通过运行list-protections命令来获取保护 ID。aws shield describe-protection \ --protection-ida1b2c3d4-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 Advanced 开发人员指南》中的指定要保护的资源。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeProtection 。 
 
- 
                    
以下代码示例演示了如何使用 describe-subscription。
- Amazon CLI
- 
             
                    检索账户的 Amazon Shield Advanced 保护的详细信息 以下 describe-subscription示例显示为账户提供的 Shield Advanced 保护的详细信息: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 Advanced 开发人员指南》中的 Amazon Shield 工作原理。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeSubscription 。 
 
- 
                    
以下代码示例演示了如何使用 disassociate-drt-log-bucket。
- Amazon CLI
- 
             
                    移除 DRT 代表您访问 Amazon S3 存储桶的授权 以下 disassociate-drt-log-bucket示例移除 DRT 与指定 S3 存储桶之间的关联。在此命令完成后,DRT 将无法再代表该账户访问该存储桶。aws shield disassociate-drt-log-bucket \ --log-bucketflow-logs-for-website-lb此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的授权 DDoS 响应团队。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DisassociateDrtLogBucket 。 
 
- 
                    
以下代码示例演示了如何使用 disassociate-drt-role。
- Amazon CLI
- 
             
                    移除 DRT 代表您缓解潜在攻击的授权 以下 disassociate-drt-role示例移除 DRT 与账户之间的关联。该调用结束后,DRT 将无法再访问或管理您的帐户。aws shield disassociate-drt-role此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的授权 DDoS 响应团队。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DisassociateDrtRole 。 
 
- 
                    
以下代码示例演示了如何使用 get-subscription-state。
- Amazon CLI
- 
             
                    检索账户 Amazon Shield Advanced 订阅的当前状态 以下 get-subscription-state示例检索账户 Shield Advanced 保护的状态。aws shield get-subscription-state输出: { "SubscriptionState": "ACTIVE" }有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的 Amazon Shield 工作原理。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetSubscriptionState 。 
 
- 
                    
以下代码示例演示了如何使用 list-attacks。
- Amazon CLI
- 
             
                    从 Amazon Shield Advanced 中检索攻击摘要 以下 list-attacks示例检索指定时间段内指定 Amazon CloudFront 分发的攻击摘要。响应包括攻击 ID,您可以将其提供给describe-attack命令以获取攻击的详细信息。aws shield list-attacks \ --resource-arnsarn:aws:cloudfront::12345678910:distribution/E1PXMP22ZVFAOR\ --start-timeFromInclusive=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 Advanced 开发人员指南》中的查看 DDoS 事件。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListAttacks 。 
 
- 
                    
以下代码示例演示了如何使用 list-protections。
- Amazon CLI
- 
             
                    从 Amazon Shield 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 Advanced 开发人员指南》中的指定要保护的资源。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListProtections 。 
 
- 
                    
以下代码示例演示了如何使用 update-emergency-contact-settings。
- Amazon CLI
- 
             
                    定义 DRT 存档中的紧急电子邮件地址 以下 update-emergency-contact-settings示例定义 DRT 在响应可疑攻击时应联系的两个电子邮件地址。aws shield update-emergency-contact-settings \ --emergency-contact-listEmailAddress=ops@example.comEmailAddress=ddos-notifications@example.com此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的 Amazon Shield 工作原理。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateEmergencyContactSettings 。 
 
- 
                    
以下代码示例演示了如何使用 update-subscription。
- Amazon CLI
- 
             
                    修改账户的 Amazon Shield Advanced 订阅 以下 update-subscription示例为该账户启用 Amazon Shield Advanced 订阅的自动续订。aws shield update-subscription \ --auto-renewENABLED此命令不生成任何输出。 有关更多信息,请参阅《Amazon Shield Advanced 开发人员指南》中的 Amazon Shield 工作原理。 - 
                    有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateSubscription 。 
 
-