Utilizzare CreateWebAcl con un AWS SDK o CLI - Esempi di codice dell'AWS SDK

Ci sono altri AWS SDK esempi disponibili nel repository AWS Doc SDK Examples GitHub .

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Utilizzare CreateWebAcl con un AWS SDK o CLI

I seguenti esempi di codice mostrano come utilizzareCreateWebAcl.

CLI
AWS CLI

Per creare un web ACL

Il create-web-acl comando seguente crea un Web ACL per uso regionale. Le istruzioni delle regole per il Web ACL sono fornite in un file in JSON formato.

aws wafv2 create-web-acl \ --name TestWebAcl \ --scope REGIONAL \ --default-action Allow={} \ --visibility-config SampledRequestsEnabled=true,CloudWatchMetricsEnabled=true,MetricName=TestWebAclMetrics \ --rules file://waf-rule.json \ --region us-west-2

Contenuto del file: //waf-rule.json:

[ { "Name":"basic-rule", "Priority":0, "Statement":{ "AndStatement":{ "Statements":[ { "ByteMatchStatement":{ "SearchString":"example.com", "FieldToMatch":{ "SingleHeader":{ "Name":"host" } }, "TextTransformations":[ { "Priority":0, "Type":"LOWERCASE" } ], "PositionalConstraint":"EXACTLY" } }, { "GeoMatchStatement":{ "CountryCodes":[ "US", "IN" ] } } ] } }, "Action":{ "Allow":{ } }, "VisibilityConfig":{ "SampledRequestsEnabled":true, "CloudWatchMetricsEnabled":true, "MetricName":"basic-rule" } } ]

Output:

{ "Summary":{ "ARN":"arn:aws:wafv2:us-west-2:123456789012:regional/webacl/TestWebAcl/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "Description":"", "Name":"TestWebAcl", "LockToken":"2294b3a1-eb60-4aa0-a86f-a3ae04329de9", "Id":"a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } }

Per ulteriori informazioni, vedere Managing and Using a Web Access Control List (WebACL) nella AWS WAF AWS Firewall Manager and AWS Shield Advanced Developer Guide.

  • Per API i dettagli, vedere CreateWebAclin AWS CLI Command Reference.

PowerShell
Strumenti per PowerShell

Esempio 1: questo comando crea un nuovo Web ACL denominato «waf-test». Si prega di notare che, secondo la API documentazione del servizio, 'DefaultAction' è una proprietà obbligatoria. Pertanto, è necessario specificare il valore per '- DefaultAction _Allow' e/o '- DefaultAction _Block '. Poiché '- DefaultAction _Allow' e '- DefaultAction _Block 'non sono le proprietà richieste, il valore '@ {}' potrebbe essere usato come segnaposto come mostrato nell'esempio precedente.

New-WAF2WebACL -Name "waf-test" -Scope REGIONAL -Region eu-west-1 -VisibilityConfig_CloudWatchMetricsEnabled $true -VisibilityConfig_SampledRequestsEnabled $true -VisibilityConfig_MetricName "waf-test" -Description "Test" -DefaultAction_Allow @{}

Output:

ARN : arn:aws:wafv2:eu-west-1:139480602983:regional/webacl/waf-test/19460b3f-db14-4b9a-8e23-a417e1eb007f Description : Test Id : 19460b3f-db14-4b9a-8e23-a417e1eb007f LockToken : 5a0cd5eb-d911-4341-b313-b429e6d6b6ab Name : waf-test
  • Per API i dettagli, vedere in Cmdlet Reference. CreateWebAclAWS Tools for PowerShell