admin管理员组文章数量:1327660
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 mand = new CloneReceiptRuleSetCommand(params);
client.send(mand)
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.
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 mand = new CloneReceiptRuleSetCommand(params);
client.send(mand)
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.
Share Improve this question edited Feb 14, 2023 at 8:18 jonrsharpe 122k30 gold badges267 silver badges474 bronze badges asked Feb 13, 2023 at 22:09 Pedro RabbiPedro Rabbi 4011 gold badge6 silver badges18 bronze badges 2- Did you read the API docs? Looks like you can still pass credentials in when you instantiate the client. But why not just set the default env vars? – jonrsharpe Commented Feb 13, 2023 at 22:13
- @jonrsharpe maybe I'm mistaken, but as far as I understood, the env vars would be attached to my puter, and I don't want that. I want that if I switch puters, the credentials be attached in some file in the GitHub repo, so that I can work normally in the other puter – Pedro Rabbi Commented Feb 13, 2023 at 22:23
1 Answer
Reset to default 9The 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 mand = new CloneReceiptRuleSetCommand(params);
client.send(mand)
References:
- Type definition for the SESClient constructor config
- Type definition of the
credentials
object - Constructor definition of the CloneReceiptRuleSetCommand
本文标签: javascriptHow to hard code credentials AWS SES JS SDK V3Stack Overflow
版权声明:本文标题:javascript - How to hard code credentials AWS SES JS SDK V3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742228760a2436823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论