11

My application has Health Status of Severe because of Target.ResponseCodeMismatch error.

I've tried following Redirection is not configured on the backend in this aws instruction . And I've changed my port to '443' and my protocol to 'HTTPS' on eb config and redeployed. It changes the Health Status to Ok but when I access my url I get the page 'Index of' only

Here is what eb status --verbose returns:

Description: Health checks failed with these codes: [301]
Reason: Target.ResponseCodeMismatch

And this is from eb config:

AWSEBV2LoadBalancerListener.aws:elbv2:listener:default:
  DefaultProcess: default
  ListenerEnabled: 'true'
  Protocol: HTTP
  Rules: null
  SSLCertificateArns: null
  SSLPolicy: null
AWSEBV2LoadBalancerListener443.aws:elbv2:listener:443:
  DefaultProcess: default
  ListenerEnabled: 'true'
  Protocol: HTTPS
  Rules: null
  SSLCertificateArns: arn:aws:acm:us-east-2:XXXX:certificate/XXXXXX
  SSLPolicy: ELBSecurityPolicy-XX-XX-XXXX  
aws:elasticbeanstalk:environment:process:default:
  DeregistrationDelay: '20'
  HealthCheckInterval: '15'
  HealthCheckPath: /      
  HealthCheckTimeout: '5'
  HealthyThresholdCount: '3'
  MatcherHTTPCode: null
  Port: '443'
  Protocol: HTTPS
sptramp
  • 897
  • 2
  • 10
  • 29

7 Answers7

37

For someone that may come across this as I did, I found the solution to be setting up the Health Check endpoint of the ELB target group to an actual URL on my website that returned an HTTP 200 code.

On the EC2 dashboard, under Load Balancing -> Target Groups, go to the tab Health Checks and edit the path to a path in your site that returns an 200 code.

enter image description here

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
filipe navas
  • 371
  • 3
  • 3
12

I had a similar problem. In my case the fix was to change the health check's "Success codes" setting from 200 to 200,301.

Jason Swett
  • 43,526
  • 67
  • 220
  • 351
1

In DotNet I added this controller that will allow anonymous access and then in EC2 > Load Balancing > Target Group set the health check path to /health

public class HealthController : Controller
{
    [AllowAnonymous]
    public IActionResult Index()
    {
        return Ok($"HEALTH: OK - {DateTime.Now}");
    }
}

enter image description here

Under Advanced Settings, include the HTTP code 302 to the expected results

enter image description here

Anton Swanevelder
  • 1,025
  • 1
  • 14
  • 31
0

Typically your app is going to get deploy exposing it's native port. In the case of java this is usually 8080, with node it's 3000. Then AWS will, as part of EB, will still a proxy of either apache or nginx in front of your app exposing port 80. It's ELB that exposes port 443 to the outside.

So you probably want to change the port and protocol to 80 / HTTP

denov
  • 11,180
  • 2
  • 27
  • 43
0

This seem to have helped me, in

"health check settings" > "Advanced health check settings"

Under: "Port" from "Traffic port" to "Override" and used "80"

Under: "Success codes"

One Instance of EB from "200" to "200,300,301,302,303,304,305,306,307,308" (In Elastic Beanstalk Health was down because of "3xx Responses")

Second Instance of EB from "200" to "200,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,422,425,426,428,429,431,451" (In Elastic Beanstalk Health was down because of "4xx Responses")

atazmin
  • 4,757
  • 1
  • 32
  • 23
0

For me, this was as simple as making sure the route that the health check is pointed to, like '/' for my example, returns a 200 result.

const router = require("express").Router();

// Health Check
router.get('/', (req, res)=>{
    res.sendStatus(200);
})

module.exports = router;
elarcoiris
  • 1,914
  • 4
  • 28
  • 30
-2

I had the following problem:

Description: Health checks failed with these codes: [400]
Reason: Target.ResponseCodeMismatch

What fixed for me was entering the Success codes value to 400.

EC2 (service) > Load Balancing (from left side menu) > Target Groups (click on Name) > Health Check (click on tab) > Edit > Advanced health check settings > Success codes = 400

abhi54
  • 22
  • 2
  • 2
    Yes, this would fix the problem, but since an HTTP 400 error code denotes a failure of the client, I don't think you'd want this in the list of success codes. – stijndepestel Aug 06 '21 at 09:58
  • @stijndepestel The thing is my AWS Environment Health is transitioning from OK to Severe without this Success code added and I found no other alternative. – abhi54 Aug 06 '21 at 10:07
  • Have you implemented and configured a health check endpoint in your API that the beanstalk service can use? Problem is, that it also uses this information for automatic recovering from failures for example, which is a lot less reliable if you add the 400 HTTP error code to the list of success codes. – stijndepestel Aug 06 '21 at 10:42
  • @stijndepestel Yes I have tried configuring `Path` to **/index.html** which is present inside templates as well as root directory, and to **/multiple** which is valid url in myenv.region.elasticbeanstalk.com/multiple while keeping Success codes to 200 – abhi54 Aug 06 '21 at 12:33
  • @stijndepestel My application uses client-side tests, so 400 errors are frequent as mentioned in [here](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/health-enhanced-rules.html?icmpid=docs_elasticbeanstalk_console). Therefore, as described in my `Description` setting `Success codes` to **400** or ignoring HTTP 4xx ([https://stackoverflow.com/a/51556599/14408583](https://stackoverflow.com/a/51556599/14408583)) can work!! – abhi54 Aug 06 '21 at 17:50