Search code examples
amazon-web-servicesamazon-ec2environment-variablesamazon-elastic-beanstalkweb-deployment

AWS environment variable


I use the GUI, and I am not familiar with the AWS CLI, nor have I used it. I am new to program development, and this is my first deployment to AWS.

There are many solutions to stack overflow using CLI, but what I am looking for is a GUI solution.

Problem:

The program needs to use environmental variables, and EB has also set the environmental variables, but it still can't work normally. (Environmental variables have been set successfully, and there is no jump error)

I’ve been stuck for 2 days, I’ve googled and read the documentation, but I can’t solve the problem.

What I use AWS services:

  • codePipeline to continuous deployment(github version 2)
  • EB to be my application (Node 10x version)

codePipeline & deploy success

Everything look fine, but website just get 502.

event error: 100.0 % of the requests are erroring with HTTP 4xx. Insufficient request rate (12.0 requests/min) to determine application health.

I check the E2C log, it said jwt need secret or key which actual value is save in process.env.TOKEN_SECRET.

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Sep 17 10:15:57 ip-172-31-14-49 web: throw new TypeError('JwtStrategy requires a secret or key');
Sep 17 10:15:57 ip-172-31-14-49 web: ^
Sep 17 10:15:57 ip-172-31-14-49 web: TypeError: JwtStrategy requires a secret or key

Sometimes the error will change to

----------------------------------------
/var/log/nginx/error.log
----------------------------------------
2021/09/17 15:55:34 [error] 9567#9567: *5385 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.35.193, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "172.31.14.49"

my code in config/passport:

let jwtOptions = {} 
jwtOptions.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken()
jwtOptions.secretOrKey = process.env.TOKEN_SECRET

My EB & E2C Environmental variables setting:

EB config variables E2C config variables

And I check the event said that the environment variable was successfully set, and there was no error message.

As you can see, I already set environmental variables, and the system also said that I was successful, but the actual operation is not the same. When the program is executed, the environment variables are still not successfully read.

*sorry for Chinese picture, I already change to English but not working . Probably is my country setting


Solution

  • Because I set the key to the environment variable and the environment tag at the same time, something went wrong.

    When I removed the environment tag, it worked normally.