Environment variables for a Node app running on an EC2 Instance

0

I have set up a CI/CD pipeline for my project. On git commits there is a trigger which runs the CodePipeline -> CodeDeploy -> EC2 setup. The EC2 instance runs an Nginx web server and Node cluster using PM2. I am using a package called dotenv to load env vars like API keys and secrets. Since we don't commit it there is no way these vars load into the Node app on EC2. I have heard about secrets manager but I am not sure. Can someone guide me on this?

fdr
已提問 2 年前檢視次數 8188 次
1 個回答
0

Good question!

There are a few different AWS-native ways you can pull env vars into your Node app on EC2.

  • AWS Secrets Manager
  • AWS System Manager Parameter Store

For secrets, AWS Secrets Managers offers more features that help with protecting and managing those secrets.

In this case, you could configure the EC2 instance to pull those variables from AWS Secrets Manager. A couple things you would need to do:

  • Store the secrets in AWS Secrets Manager
  • Update the EC2 Instance Profile IAM Role to have permissions to pull from AWS Secrets Manager
  • Encrypt the secrets in AWS Secrets Manager and ensure the instance has access to use the KMS Key.

Now for Secret Retrieval:

Additional:

For more in-depth AWS guides, check out: https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html

jsonc
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南