如果使用AWS_CONFIG_FILE,则配置中缺少凭据,请设置AWS_SDK_LOAD_CONFIG = 1 [英] Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
问题描述
当我尝试在项目中使用AWS凭证时,它给出了一个错误,我面临着难以找到解决方案的问题,当我在同一文件中使用凭证时,它起作用了,但是当我尝试使用时.代码
when I am trying to use Aws credentials in my project it gives an error i am facing hard to find the solution and when i am using credentials in the same file it worked but when i am trying to use.here is my tried code
const AWS = require('aws-sdk');
const SESConfig = {
apiVersion: "2010-12-01",
accessKeyId: process.env.AWS_SECRET_KEY,
accessSecretKey: process.env.AWS_SECRET_KEY,
region: "us-east-1"
}
AWS.config.update(SESConfig);
var sns = new AWS.SNS()
var sns = new AWS.SNS();
function sendSMS(to_number, message, cb) {
sns.publish({
Message: message,
Subject: 'Admin',
PhoneNumber:to_number
}, cb);
}
// Example
const PhoneNumberArray = ['any mobile number']
PhoneNumberArray.forEach(number => {
sendSMS(number, "Lorem Ipsum is simply dummy text of the printing and typesetting industry.", (err, result)=>{
console.log("RESULTS: ",err,result)
})
})
推荐答案
默认情况下,SDK检测到您环境中设置的AWS凭证,并使用它们来签署对AWS的请求.这样一来,您就无需管理应用程序中的凭据.
By default, the SDK detects AWS credentials set in your environment and uses them to sign requests to AWS. That way you don’t need to manage credentials in your applications.
$ export AWS_ACCESS_KEY_ID="your_key_id"
$ export AWS_SECRET_ACCESS_KEY="your_secret_key"
您还可以添加$ export AWS_SESSION_TOKEN='your_token'
(可选)
请参见 aws-sdk 了解更多信息.
或创建一个~/.aws/credentials
文件并添加:
or create a ~/.aws/credentials
file and add:
[default]
aws_access_key_id = <YOUR_ACCESS_KEY_ID>
aws_secret_access_key = <YOUR_SECRET_ACCESS_KEY>
请参见 aws 以获得更多详细信息.
See aws for more details.
这篇关于如果使用AWS_CONFIG_FILE,则配置中缺少凭据,请设置AWS_SDK_LOAD_CONFIG = 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!