How do you put up a maintenance page for AWS when your instances are behind an ELB?

后端 未结 6 1395
滥情空心
滥情空心 2021-01-30 16:32

How do you put up a maintenance page in AWS when you want to deploy new versions of your application behind an ELB? We want to have the ELB route traffic to the maintenance inst

6条回答
  •  迷失自我
    2021-01-30 17:04

    Came up with another solution that's working great for us. Here are the required steps to get a simple 503 http response:

    1. Replicate your EB environment to create another one, call it something like app-environment-maintenance, for instance.
    2. Change the configuration for autoscaling and set the min and max servers both to zero. This won't cost you any EC2 servers and the environment will turn grey and sit in your list.
    3. Finally, you can use the AWS CLI to now swap the environment CNAME to take your main environment into maintenance mode. For instance:

      aws elasticbeanstalk swap-environment-cnames \
          --profile "$awsProfile" \
          --region "$awsRegion" \
          --output text \
          --source-environment-name app-prod \
          --destination-environment-name app-prod-maintenance
      

    This would swap your app-prod environment into maintenance mode. It would cause the ELB to throw a 503 since there aren't any running EC2 instances and then Cloudfront can catch the 503 and return your custom 503 error page, should you wish, as described below.


    Bonus configuration for custom error pages using Cloudfront:

    We use Cloudfront, as many people will for HTTPS, etc. Cloudfront has error pages. This is a requirement.

    1. Create a new S3 website hosting bucket with your error pages. Consider creating separate files for response codes, 503, etc. See #6 for directory requirements and routes.
    2. Add the S3 bucket to your Cloudfront distribution.
    3. Add a new behavior to your Cloudfront distribution for a route like /error/*.
    4. Setup an error pages in Cloudfront to handle 503 response codes and point it to your S3 bucket route, like /error/503-error.html

    Now, when your ELB thorws a 503, your custom error page will be displayed.

    And that's it. I know there are quite a few steps to get the custom error pages and I tried a lot of the suggested options out there including Route53, etc. But all of these have issues with how they work with ELBs and Cloudfront, etc.

    Note that after you swap the hostnames for the environments, it takes about a minute or so to propagate.

提交回复
热议问题