如何硬编码 AWS SES JS SDK V3 的凭据

huangapple go评论64阅读模式
英文:

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 中,您需要提供 OriginalRuleSetNameRuleSetName

因此,代码应如下所示:

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)

参考链接:

英文:

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:

huangapple
  • 本文由 发表于 2023年2月14日 06:09:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定