I have used aws sns for message service. I have used dot env for storing credentials for aws-sdk. App is working fine in localhost but when i deploy my node app to AWS EC2 following error occurs: Error [CredentialsError]: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 app.js
const dotenv = require("dotenv");
dotenv.config();
const AWS = require("aws-sdk");
AWS.config.update({
accessKeyId: process.env.ID,
secretAccessKey: process.env.KEY,
region: process.env.REGION,
});

Install CLI in EC2 using following commands:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
unzip awscliv2.zip
sudo ./aws/install
sudo ./aws/install -i /usr/local/aws-cli -b /usr/local/bin
then in your project folder before starting server export keys:
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-west-2
Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html, https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With