我已使用aws sns进行消息服务。我已经使用dot env来存储aws-sdk的凭据。应用程序在本地主机上运行良好,但是当我将节点应用程序部署到AWS EC2时,会发生以下错误:错误[CredentialsError]:配置中缺少凭据,如果使用AWS_CONFIG_FILE,请设置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,
});
答案 0 :(得分:0)
使用以下命令在EC2中安装CLI:
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
然后在启动服务器导出密钥之前,在项目文件夹中:
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-west-2
参考:https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html,https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html