やりたかったこと
前回、AWS WAF を CloudFormation から適用した
本当はCloudFormation 経由で AWS WAF Classic の Rate-based ルールをデプロイしたかった。
できなかった。
実践
The referenced item does not exist. (Service: AWSWAFRegional; Status Code: 400; Error Code: WAFNonexistentItemException;
こういう CloudFormation Template を作成した。
AWSTemplateFormatVersion: "2010-09-09" Resources: MyWebACL: Type: "AWS::WAFRegional::WebACL" Properties: Name: "MyWebACL" MetricName: "MyWebACL" DefaultAction: Type: "ALLOW" Rules: - Action : Type: "COUNT" Priority: 1 RuleId: Ref: "MyIPSetRateBasedRule" MyIPSetRateBasedRule: Type: "AWS::WAFRegional::RateBasedRule" Properties: Name: "MyIPSetRateBasedRule" MetricName: "MyIPSetRateBasedRule" RateKey: "IP" RateLimit: 8000 |
これをデプロイするとエラーとなる。
$ aws cloudformation deploy --stack-name web-acl-test --template-file create_waf_v1_rate.yaml Waiting for changeset to be created.. Waiting for stack create/update to complete Failed to create/update the stack. Run the following command to fetch the list of events leading up to the failure aws cloudformation describe-stack-events --stack-name web-acl-test
エラーの部分。WebACL と Rate-basedルールを紐付けるところで失敗している。
aws cloudformation describe-stack-events --stack-name web-acl-test
{ "StackId": "arn:aws:cloudformation:ap-northeast-1:111122223333:stack/web-acl-test2/fadf23e0-71d2-11ea-ab16-0a6f9 c86115e", "EventId": "MyWebACL-CREATE_FAILED-2020-03-29T15:38:48.727Z", "StackName": "web-acl-test2", "LogicalResourceId": "MyWebACL", "PhysicalResourceId": "a67cfacc-237f-4695-95be-e5aeb3066398", "ResourceType": "AWS::WAFRegional::WebACL", "Timestamp": "2020-03-29T15:38:48.727000+00:00", "ResourceStatus": "CREATE_FAILED", "ResourceStatusReason": "The referenced item does not exist. (Service: AWSWAFRegional; Status Code: 400; Error Code: WAFNonexistentItemException; Request ID: df5e9a0d-f46d-49e5-b02d-0ed6a7406482)", "ResourceProperties": "{\"MetricName\":\"MyWebACL\",\"DefaultAction\":{\"Type\":\"ALLOW\"},\"Rules\":[{\"Action\":{\"Type\":\"COUNT\"},\"Priority\":\"1\",\"RuleId\":\"6ebe2270-fb7c-4be5-addc-668fdd8ca821\"}],\"Name\":\"MyWebACL\"}" }, { "StackId": "arn:aws:cloudformation:ap-northeast-1:111122223333:stack/web-acl-test2/fadf23e0-71d2-11ea-ab16-0a6f9c86115e", "EventId": "MyWebACL-CREATE_IN_PROGRESS-2020-03-29T15:38:47.619Z", "StackName": "web-acl-test2", "LogicalResourceId": "MyWebACL", "PhysicalResourceId": "a67cfacc-237f-4695-95be-e5aeb3066398", "ResourceType": "AWS::WAFRegional::WebACL", "Timestamp": "2020-03-29T15:38:47.619000+00:00", "ResourceStatus": "CREATE_IN_PROGRESS", "ResourceStatusReason": "Resource creation Initiated", "ResourceProperties": "{\"MetricName\":\"MyWebACL\",\"DefaultAction\":{\"Type\":\"ALLOW\"},\"Rules\":[{\"Action\":{\"Type\":\"COUNT\"},\"Priority\":\"1\",\"RuleId\":\"6ebe2270-fb7c-4be5-addc-668fdd8ca821\"}],\"Name\":\"MyWebACL\"}" }, { "StackId": "arn:aws:cloudformation:ap-northeast-1:11122223333:stack/web-acl-test2/fadf23e0-71d2-11ea-ab16-0a6f9c86115e", "EventId": "MyIPSetRateBasedRule-CREATE_COMPLETE-2020-03-29T15:38:43.188Z", "StackName": "web-acl-test2", "LogicalResourceId": "MyIPSetRateBasedRule", "PhysicalResourceId": "6ebe2270-fb7c-4be5-addc-668fdd8ca821", "ResourceType": "AWS::WAFRegional::RateBasedRule", "Timestamp": "2020-03-29T15:38:43.188000+00:00", "ResourceStatus": "CREATE_COMPLETE", "ResourceProperties": "{\"MetricName\":\"MyIPSetRateBasedRule\",\"RateLimit\":\"8000\",\"RateKey\":\"IP\",\"Name\":\"MyIPSetRateBasedRule\"}" } |
API Reference では下記で、WAF と ALB の紐付けを先にやらないといけないのか?とか考えていたが。。
AWS WAF couldn’t perform the operation because your resource doesn’t exist.
AWS::WAFRegional::RateBasedRule
AWS::WAFRegional::RateBasedRuleを読むと全て書いてあった。
レートベースのルールは、CloudFormation を使用してのみ作成できます。CloudFormation を介して作成したレートベースのルールをウェブ ACL に追加するには、AWS WAF コンソール、API、またはコマンドラインインターフェイス (CLI) を使用します。詳細については、「UpdateWebACL」を参照してください。
WebACL に Rate-based ルールを追加するにはコンソール経由か、API、CLI 経由出ないと駄目とのこと。
コメント