英文:
How to hard code credentials AWS SES JS SDK V3
问题
AWS强制我升级到SDK V3,现在我在设置我的凭据方面遇到了很大的困难。以前,它们是硬编码的,像这样:
AWS.config.update({
apiVersion: "2010-12-01",
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY",
region: "us-east-1",
});
但现在AWS
包已被弃用,推荐使用模块化的@aws-sdk/client-ses
。
如何在这个新版本的SDK中像以前一样硬编码我的凭据?
我目前有以下内容:
import {
SESClient,
CloneReceiptRuleSetCommand,
} from "@aws-sdk/client-ses";
const client = new SESClient({
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY",
region: "us-east-1",
});
const command = new CloneReceiptRuleSetCommand(params);
client.send(command)
但它给我返回了错误信息:“CredentialsProviderError: 无法从任何提供程序加载凭据”
附注:我了解硬编码凭据的劣势,但这对于这个特定应用程序不是问题。这是一个后端Node.js服务,只有我需要访问它。
英文:
AWS forced me to upgrade do SDK V3, and now I'm having such a hard time setting up my credentials. They used to be hard-coded like:
AWS.config.update({
apiVersion: "2010-12-01",
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY",
region: "us-east-1",
});
But now the AWS
package is deprecated in favor of the modularized @aws-sdk/client-ses
.
How to hard code my credentials as I used to do in this new version of the SDK?
What I have so far:
import {
SESClient,
CloneReceiptRuleSetCommand,
} from "@aws-sdk/client-ses";
const client = new SESClient({
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY",
region: "us-east-1",
});
const command = new CloneReceiptRuleSetCommand(params);
client.send(command)
But it returns me the error "CredentialsProviderError: Could not load credentials from any providers"
P.S.: I know the disadvantages of hard-coding credentials, but this is not a issue for this application in particular. It's a backend Node.js service, and only I need to have access to it.
答案1
得分: 4
关键和秘钥需要位于配置对象的 credentials
属性中。
此外,在 CloneReceiptRuleSetCommand
中,您需要提供 OriginalRuleSetName
和 RuleSetName
。
因此,代码应如下所示:
import {
SESClient,
CloneReceiptRuleSetCommand,
} from "@aws-sdk/client-ses";
const client = new SESClient({
credentials: {
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY"
},
region: "us-east-1",
});
const params = {
OriginalRuleSetName: 'RULESET_TO_CLONE',
RuleSetName: 'TARGET_RULESET'
}
const command = new CloneReceiptRuleSetCommand(params);
client.send(command)
参考链接:
-
CloneReceiptRuleSetCommand
构造函数的定义3
英文:
The key and the secret need to be in the credentials
object of the configuration object.
Also, for CloneReceiptRuleSetCommand
, you need to provide OriginalRuleSetName
and RuleSetName
.
So, it should be like this:
import {
SESClient,
CloneReceiptRuleSetCommand,
} from "@aws-sdk/client-ses";
const client = new SESClient({
credentials: {
accessKeyId: "MYKEY",
secretAccessKey: "MYOTHERKEY"
},
region: "us-east-1",
});
const params = {
OriginalRuleSetName: 'RULESET_TO_CLONE',
RuleSetName: 'TARGET_RULESET'
}
const command = new CloneReceiptRuleSetCommand(params);
client.send(command)
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论