LoginSignup
1
0

事前確認

title: 事前確認
$ AWS_REGION=us-east-1
$ STACK_NAME=<CloudFormationスタック名>
$ WAF_PREFIX=<WAFプレフィックス名>
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.DefaultAction"
{
    "Block": {
        "CustomResponse": {
            "ResponseCode": 503
        }
    }
}
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.Rules[?Name==\`${WAF_PREFIX}-Rule-RateLimit\`].Action"
[
    {
        "Block": {
            "CustomResponse": {
                "ResponseCode": 403
            }
        }
    }
]

※作業が終わったら、必ず「AWS_REGION=ap-northeast-1」を実行すること。
 実行を忘れるとバージニア北部でAWS CLIを実行するので、
 東京リージョンのリソースが参照できなくなる。

メンテナンスモード切替

メンテナンスモード解除

MaintenanceModeパラメータをfalseに設定
※update-stack --use-previous-templateで現在のスタックを更新できるが、
 --parametersには変更のないパラメータも UsePreviousValue=true で全て指定しないと
 エラーになる

title: メンテナンスモード解除

$ aws cloudformation update-stack --stack-name $STACK_NAME --use-previous-template --parameters $(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query 'Stacks[0].Parameters[?ParameterKey!=`MaintenanceMode`].ParameterKey' | tr '\t' '\n' | sed -E 's/(^.*$)/ParameterKey=\1,UsePreviousValue=true/' | tr '\n' ' ') ParameterKey=MaintenanceMode,ParameterValue=false
$ aws cloudformation wait stack-update-complete --stack-name $STACK_NAME

デフォルトアクション確認

デフォルトアクションがメンテナンスモード解除状態であることを確認する。

title: デフォルトアクション確認
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.DefaultAction"
{
    "Allow": {}
}

メンテナンスモード設定

MaintenanceModeパラメータをtrueに設定

title: メンテナンスモード設定
$ aws cloudformation update-stack --stack-name $STACK_NAME --use-previous-template --parameters $(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query 'Stacks[0].Parameters[?ParameterKey!=`MaintenanceMode`].ParameterKey' | tr '\t' '\n' | sed -E 's/(^.*$)/ParameterKey=\1,UsePreviousValue=true/' | tr '\n' ' ') ParameterKey=MaintenanceMode,ParameterValue=true
$ aws cloudformation wait stack-update-complete --stack-name $STACK_NAME

デフォルトアクション確認

デフォルトアクションがメンテナンスモード設定状態であることを確認する。

title: デフォルトアクション確認
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.DefaultAction"
{
    "Block": {
        "CustomResponse": {
            "ResponseCode": 503
        }
    }
}

テストモード切替

テストモード設定

TestModeパラメータをtrueに設定

title: テストモード設定
$ aws cloudformation update-stack --stack-name $STACK_NAME --use-previous-template --parameters $(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query 'Stacks[0].Parameters[?ParameterKey!=`TestMode`].ParameterKey' | tr '\t' '\n' | sed -E 's/(^.*$)/ParameterKey=\1,UsePreviousValue=true/' | tr '\n' ' ') ParameterKey=TestMode,ParameterValue=true
$ aws cloudformation wait stack-update-complete --stack-name $STACK_NAME

ルールアクション確認

ルールアクションがテストモード設定状態になっていることを確認

title: ルールアクション確認
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.Rules[?Name==\`${WAF_PREFIX}-Rule-RateLimit\`].Action"
[
    {
        "Count": {}
    }
]

テストモード解除

TestModeパラメータをfalseに設定

title: テストモード解除
$ aws cloudformation update-stack --stack-name $STACK_NAME --use-previous-template --parameters $(aws cloudformation describe-stacks --stack-name $STACK_NAME --output text --query 'Stacks[0].Parameters[?ParameterKey!=`TestMode`].ParameterKey' | tr '\t' '\n' | sed -E 's/(^.*$)/ParameterKey=\1,UsePreviousValue=true/' | tr '\n' ' ') ParameterKey=TestMode,ParameterValue=false
$ aws cloudformation wait stack-update-complete --stack-name $STACK_NAME

ルールアクション確認

ルールアクションがテストモード解除状態になっていることを確認

title: ルールアクション確認
$ aws wafv2 get-web-acl --name "${WAF_PREFIX}-WebACL" --scope CLOUDFRONT --id $(aws wafv2 list-web-acls --scope CLOUDFRONT --output text --query "WebACLs[?Name==\`${WAF_PREFIX}-WebACL\`].Id") --query "WebACL.Rules[?Name==\`${WAF_PREFIX}-Rule-RateLimit\`].Action"
[
    {
        "Block": {
            "CustomResponse": {
                "ResponseCode": 403
            }
        }
    }
]
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0