Question: How do I troubleshoot a 502: "The request could not be satisfied" error from CloudFront?

I configured an Amazon CloudFront distribution with a custom domain. When requesting the alternative Canonical Name record (CNAME) domain over CloudFront, I get a 502 Error response with the message "The request could not be satisfied."Short descriptionA 502 error occurs when CloudFront is unable to connect to the origin. See the following sections for the causes of the error, and how to troubleshoot.

ResolutionCloudFront can't establish a TCP connection with the origin serverBy default, CloudFront connects to the origin over port 80 (for HTTP) and port 443 (for HTTPS). If the origin doesn't allow traffic over these ports, or blocks the CloudFront IP address's connection, then the TCP connection fails. The failure produces a 502 error. To resolve, confirm that the CloudFront distribution's Protocol setting is set to the correct port for HTTP or HTTPS connections.To test port connectivity, run the following command:telnet ORIGIN_DOMAIN/ORIGIN_IP PORTNote: For ORIGIN_DOMAIN, enter the ID of your origin domain. For ORIGIN_IP, enter the IP address of your origin. For PORT, enter the port number you're using to connect to the origin.SSL/TLS negotiation with the origin server failedIf the SSL/TLS transaction fails, then the connection between CloudFront and the origin fails and produces a 502 error. See the following sections for causes of an SSL/TLS transaction failure, and how to resolve them.SSL certificate doesn't match the domain nameThe SSL certificate at the origin must include or cover one of the following domain names:The origin domain name in the certificate's Common Name field or Subject Alternative Names field.The host header's domain name for incoming viewer host headers that are forwarded to the origin in the CloudFront distribution.To check for the Common Name and Subject Alternative Names in the certificate, run the following command:$ openssl s_client -connect DOMAIN:443 -servername SERVER_DOMAIN | openssl x509 -text | grep -E '(CN|Alternative)' -A 2Note: For DOMAIN, enter the origin domain name. For SERVER_DOMAIN enter the origin domain name. Or, if the viewer host header is forwarded to the origin), for SERVER_DOMAIN, enter the incoming host header value.If the following are true, then configure the cache policy or origin request policy to include the host header:The SSL certificate's common name or subject alternate name (SAN) includes the viewer host header value.The host header is not forwarded to the origin.Origin Certificate is expired, not trusted, or self-signedThe certificate installed the custom origin must be signed by a trusted Certificate Authority. The certificate authorities trusted by CloudFront are found on the Mozilla included CA certificate list on the Mozilla website.CloudFront doesn't support self-signed certificates for SSL set up with the origin. Self-signed certificates are issued by the organizations themselves or generated locally on a web-server instead of being issued by a trusted Certificate Authority.To check if your origin certificate is expired, run the following OpenSSL command. In the output, find the Not Before and Not After parameters. Confirm that the current date and time is within the certificate's validity period.$ openssl s_client -connect DOMAIN:443 -servername SERVER_DOMAIN | openssl x509 -text | grep Validity -A 3Note: For DOMAIN, enter the origin domain name. For SERVER_DOMAIN enter the origin domain name. Or, if the viewer host header is forwarded to the origin), for SERVER_DOMAIN, enter the incoming host header value.Missing intermediate CA certificates or the incorrect order of intermediate certificates causes failure between HTTPS communication and the origin. To check the certificate chain, run the following command.$ openssl s_client -showcerts -connect DOMAIN:443 -servername SERVER_DOMAINNote: For DOMAIN, enter the origin domain name and for SERVER_DOMAIN enter the origin domain name. Or, if the viewer host header is forwarded to the origin), for SERVER_DOMAIN, enter the incoming host header value.The origin's cipher suit isn't supported by CloudFrontSSL/TLS transactions between CloudFront and Origin fail if there is no common negotiated ciphers suite. To confirm you're using the correct cipher suite, see Supported protocols and ciphers between CloudFront and the origin.You can also use an SSL server test tool to check if your origin domain name is included on the list of supported ciphers.CloudFront can't resolve the origin IP addressIf CloudFront can't resolve the origin domain, then it returns 502 error. To troubleshoot this, use a dig/nslookup command to check if the origin domain resolves to an IP.Linux:$ dig ORIGIN_DOMAIN_NAMEWindows:nslookup ORIGIN_DOMAIN_NAMENote: For ORIGIN_DOMAIN_NAME, enter the origin domain name.If successful, then the command returns the IP of the origin domain name. Use a DNS checker tool to check for DNS resolution across different geographies.The error is caused by upstream originThe custom origin defined in the CloudFront distribution can be a proxy, Content Delivery Network (CDN) hostname, or load balancer connected to the actual origin. If any of these intermediary services fails to connect to the origin, then a 502 error is returned to CloudFront. To resolve this, work with your service provider.The Lambda@Edge function associated with the CloudFront distribution failed validationIf the Lambda@Edge function returns a response to CloudFront that's not valid, then CloudFront returns a 502 error. To resolve this, check your Lambda@Edge function for the following common issues:Returned JSON objectMissing required fieldsInvalid object in the responseAdding or updating disallowed or read-only headersExceeding the maximum body sizeCharacters or values that aren't validFor more information, see Testing and debugging Lambda@Edge functions.