Class: AWSCDK::CloudFront::CfnDistribution::CustomErrorResponseProperty

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
cloud_front/cfn_distribution.rb

Overview

A complex type that controls:.

  • Whether CloudFront replaces HTTP status codes in the 4xx and 5xx range with custom error messages before returning the response to the viewer.
  • How long CloudFront caches HTTP status codes in the 4xx and 5xx range.

For more information about custom error pages, see Customizing Error Responses in the Amazon CloudFront Developer Guide .

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_code:, error_caching_min_ttl: nil, response_code: nil, response_page_path: nil) ⇒ CustomErrorResponseProperty

Returns a new instance of CustomErrorResponseProperty.

Parameters:

  • error_code (Numeric)

    The HTTP status code for which you want to specify a custom error page and/or a caching duration.

  • error_caching_min_ttl (Numeric, nil) (defaults to: nil)

    The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified in ErrorCode .

  • response_code (Numeric, nil) (defaults to: nil)

    The HTTP status code that you want CloudFront to return to the viewer along with the custom error page.

  • response_page_path (String, nil) (defaults to: nil)

    The path to the custom error page that you want CloudFront to return to a viewer when your origin returns the HTTP status code specified by ErrorCode , for example, /4xx-errors/403-forbidden.html . If you want to store your objects and your custom error pages in different locations, your distribution must include a cache behavior for which the following is true:.



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'cloud_front/cfn_distribution.rb', line 1043

def initialize(error_code:, error_caching_min_ttl: nil, response_code: nil, response_page_path: nil)
  @error_code = error_code
  Jsii::Type.check_type(@error_code, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "errorCode")
  @error_caching_min_ttl = error_caching_min_ttl
  Jsii::Type.check_type(@error_caching_min_ttl, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "errorCachingMinTtl") unless @error_caching_min_ttl.nil?
  @response_code = response_code
  Jsii::Type.check_type(@response_code, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "responseCode") unless @response_code.nil?
  @response_page_path = response_page_path
  Jsii::Type.check_type(@response_page_path, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "responsePagePath") unless @response_page_path.nil?
end

Instance Attribute Details

#error_caching_min_ttlNumeric? (readonly)

Note:

Default: - 300

The minimum amount of time, in seconds, that you want CloudFront to cache the HTTP status code specified in ErrorCode .

When this time period has elapsed, CloudFront queries your origin to see whether the problem that caused the error has been resolved and the requested object is now available.

For more information, see Customizing Error Responses in the Amazon CloudFront Developer Guide .



1068
1069
1070
# File 'cloud_front/cfn_distribution.rb', line 1068

def error_caching_min_ttl
  @error_caching_min_ttl
end

#error_codeNumeric (readonly)

The HTTP status code for which you want to specify a custom error page and/or a caching duration.



1058
1059
1060
# File 'cloud_front/cfn_distribution.rb', line 1058

def error_code
  @error_code
end

#response_codeNumeric? (readonly)

The HTTP status code that you want CloudFront to return to the viewer along with the custom error page.

There are a variety of reasons that you might want CloudFront to return a status code different from the status code that your origin returned to CloudFront, for example:

  • Some Internet devices (some firewalls and corporate proxies, for example) intercept HTTP 4xx and 5xx and prevent the response from being returned to the viewer. If you substitute 200 , the response typically won't be intercepted.
  • If you don't care about distinguishing among different client errors or server errors, you can specify 400 or 500 as the ResponseCode for all 4xx or 5xx errors.
  • You might want to return a 200 status code (OK) and static website so your customers don't know that your website is down.

If you specify a value for ResponseCode , you must also specify a value for ResponsePagePath .



1081
1082
1083
# File 'cloud_front/cfn_distribution.rb', line 1081

def response_code
  @response_code
end

#response_page_pathString? (readonly)

The path to the custom error page that you want CloudFront to return to a viewer when your origin returns the HTTP status code specified by ErrorCode , for example, /4xx-errors/403-forbidden.html . If you want to store your objects and your custom error pages in different locations, your distribution must include a cache behavior for which the following is true:.

  • The value of PathPattern matches the path to your custom error messages. For example, suppose you saved custom error pages for 4xx errors in an Amazon S3 bucket in a directory named /4xx-errors . Your distribution must include a cache behavior for which the path pattern routes requests for your custom error pages to that location, for example, /4xx-errors/* .
  • The value of TargetOriginId specifies the value of the ID element for the origin that contains your custom error pages.

If you specify a value for ResponsePagePath , you must also specify a value for ResponseCode .

We recommend that you store custom error pages in an Amazon S3 bucket. If you store custom error pages on an HTTP server and the server starts to return 5xx errors, CloudFront can't get the files that you want to return to viewers because the origin server is unavailable.



1093
1094
1095
# File 'cloud_front/cfn_distribution.rb', line 1093

def response_page_path
  @response_page_path
end

Class Method Details

.jsii_propertiesObject



1095
1096
1097
1098
1099
1100
1101
1102
# File 'cloud_front/cfn_distribution.rb', line 1095

def self.jsii_properties
  {
    :error_code => "errorCode",
    :error_caching_min_ttl => "errorCachingMinTtl",
    :response_code => "responseCode",
    :response_page_path => "responsePagePath",
  }
end

Instance Method Details

#to_jsiiObject



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'cloud_front/cfn_distribution.rb', line 1104

def to_jsii
  result = {}
  result.merge!({
    "errorCode" => @error_code,
    "errorCachingMinTtl" => @error_caching_min_ttl,
    "responseCode" => @response_code,
    "responsePagePath" => @response_page_path,
  })
  result.compact
end