Keep getting "502 Bad Gateway" when clicking on NodeJS app domain URL

0

Is anyone else having issues deploying NodeJS applications to Elastic Beanstalk? For some reason, I keep continuously getting a "502 Bad Gateway" message after clicking the application domain URL that appears during and after the app deployment.

When I check the health check, I always get a "Severe" status and an INFO message that says:

Environment health has transitioned from Pending to Severe. ELB processes are not healthy on all instances. None of the instances are sending data. 50.0 % of the requests to the ELB are failing with HTTP 5xx. Insufficient request rate (3.0 requests/min) to determine application health (7 minutes ago). ELB health is failing or not available for all instances

I SSH'ed into the EC2 instance hosting the app, and when I check the ebengine.log in /var/log and I get an error stating the following:

[ERROR] Failed to list S3 bucket, err: NoCredentialProviders: no valid providers in chain. Deprecated. For verbose messaging see aws.Config.CredentialsChainVerboseErrors

This is weird because I assigned the "AmazonS3FullAccess" permission to the account I'm using to deploy nodeJS on Elastic Beanstalk.

I'm not sure what I'm doing wrong. I added my account using the aws CLI to have full Administrator Access. I also added permissions for Administrator Access for Elastic Beanstalk. My access key and secret seem to be properly stored in ~/.aws/credentials.

I've been following this tutorial over and over again and getting the same result which is 502 bad gateway - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html

I even followed along this video here, but I still get the same "502 bad gateway" message while the user in this video is able to browse to the app domain URL with no such error message - https://www.youtube.com/watch?v=wARuLJNJiHA

I've tried the workaround mentioned here which was to create an extra config folder with extra NodeJS port configuration, but I still get the same error - https://repost.aws/questions/QUmkzeReLfQ4Kwy2K1nmzYYw/simple-node-js-app-gets-502-bad-gateway

I've filed an AWS ticket with technical support, but no one has responded or picked up the ticket.

At this point, I'm thinking that there's something broken or misconfigured within my account.

ziakq
asked 6 months ago454 views
2 Answers
1
Accepted Answer

This is weird because I assigned the "AmazonS3FullAccess" permission to the account I'm using to deploy nodeJS on Elastic Beanstalk.

The EC2 instance needs to have an IAM role associated with it that grants AmazonS3FullAccess. Deploying the stack with an account that has that permission doesn't mean that the resources that are deployed will inherit the privileges of that account.

In IAM, create a role to be used by an AWS service and select EC2 as that service, then attach the AmazonS3FullAccess policy to this new role.

That's the condensed version, full details are at https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html and https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

I'm not certain this will solve your 502 error (although it might, depending on how your app works) but it should help with the [ERROR] Failed to list S3 bucket.

profile picture
EXPERT
Steve_M
answered 6 months ago
profile picture
EXPERT
reviewed 6 months ago
  • Thank you for the reply!

    I just tried to deploy a sample NodeJS application on Elastic Beanstalk just right now, and the result was that...... it succeeded! I no longer get the "Severe" healthcheck status, but instead, I get an "OK" status, and I'm able to browse to the app domain URL without any issues.

    Reading your reply, I went ahead and turned my attention to recreate the "aws-elasticbeanstalk-ec2-role" that we need for using Elastic Beanstalk. I think I had 5 permissions in there initially, and my hunch is that the "service" field in the trust entities config wasn't set to "ec2.amazonaws.com", but might've been set to something else like "elasticbeanstalk.amazonaws.com". What I ended up doing was selecting "AWSElasticBeanstalkMulticontainerDocker", "AWSElasticBeanstalkWebTier", and "AWSElasticBeanstalkWorkerTier" as the permissions, and set the service to correspond to "ec2.amazonaws.com", and created the "aws-elasticbeanstalk-ec2-role" role.

    It seems my issue boiled down to improper configuration / creation of the "aws-elasticbeanstalk-ec2-role" role that we need to use Elastic Beanstalk.

    Thank you again for the reply!

0

Thank you for the reply!

I just tried to deploy a sample NodeJS application on Elastic Beanstalk just right now, and the result was that...... it succeeded! I no longer get the "Severe" healthcheck status, but instead, I get an "OK" status, and I'm able to browse to the app domain URL without any issues.

Reading your reply, I went ahead and turned my attention to recreate the "aws-elasticbeanstalk-ec2-role" that we need for using Elastic Beanstalk. I think I had 5 permissions in there initially, and my hunch is that the "service" field in the trust entities config wasn't set to "ec2.amazonaws.com", but might've been set to something else like "elasticbeanstalk.amazonaws.com". What I ended up doing was selecting "AWSElasticBeanstalkMulticontainerDocker", "AWSElasticBeanstalkWebTier", and "AWSElasticBeanstalkWorkerTier" as the permissions, and set the service to correspond to "ec2.amazonaws.com", and created the "aws-elasticbeanstalk-ec2-role" role. For anyone else reading, I used these instructions to accomplish this - https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/iam-instanceprofile.html

It seems my particular issue boiled down to improper configuration / creation of the "aws-elasticbeanstalk-ec2-role" role that we need to use Elastic Beanstalk.

Thank you again for the reply!

ziakq
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions