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:
- AWS Guide: https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets.html
- Caching Secrets to Improve Performance: https://docs.aws.amazon.com/secretsmanager/latest/userguide/use-client-side-caching.html
- Security of Secrets Manager: https://docs.aws.amazon.com/secretsmanager/latest/userguide/security.html
- If you're looking to do things on the EC2 instance launch, check out user-data: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
For more in-depth AWS guides, check out: https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html
How to set up cross-account deploymetn fromCodeCommit repo to EC2 instance in another accountasked 6 months ago
How to keep a process running on my EC2 instance via cloud9asked 3 years ago
How to perform CodePipeline ECS deployment based on Git tagAccepted Answerasked a year ago
AWS CodeDeploy with Private Git ServerAccepted Answerasked 2 years ago
Environment variables for a Node app running on an EC2 Instanceasked a year ago
Ruby version mismatch while deploying Rails App with CodeDeploy and CodePipeline Scripts on Ubuntu 20.0 EC2asked 5 months ago
Issue with CDK version v1 running on CICD image serverasked 5 months ago
Stop CodePipeline from triggering on every GitHub commit/pushAccepted Answerasked 2 years ago
How to deploy frontend and backend in one CICD (CodePipeline)?asked 10 hours ago
CodeDeploy Environment Variables On Windowsasked 9 months ago