3
votes

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,
});

enter image description here

1

1 Answers

1
votes

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