@aws-sdk/client-sns 发送短信时没有任何反应

问题描述 投票:0回答:1

使用

aws-sdk
v2 以前工作得很好。 我现在尝试使用 v3,不知怎的,我得到了很好的回应,但从未收到短信。我想知道我是否缺少一些设置。

以下是我采取的步骤。

  1. 创建了一项新政策只是为了发布 sns
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "sns:Publish",
            "Resource": "*"
        }
    ]
}
  1. 用户已附加到策略,然后为用户创建

    access token
    +
    secret access token

  2. 已创建代码。

import { PublishCommand, SNSClient } from '@aws-sdk/client-sns';

export const sendSms = async () => {

  try {
    const client = new SNSClient({credentials: {
      accessKeyId: process.env.AWS_ACCESS_KEY as string,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string
      }});

    const input = { // PublishInput
      PhoneNumber: "+16045181234",
      Message: "test message", // required
    };
    const command = new PublishCommand(input);
    const response = await client.send(command);

    console.log(new Date());
    console.log(response, 'response ');

    return;
  } catch (e: any) {
      console.log(e, 'SEND SMS');
  }
}

  1. 得到回复
{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '6c3f80ea-3ff2-5c38-bda6-dd6e27661c74',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  MessageId: 'a94988b1-ba63-5f5b-a647-d535a2f78f17'
}

但在移动设备上根本没有收到任何消息,也没有抛出任何错误。

提前感谢您的任何建议或意见。

javascript amazon-web-services sms amazon-sns aws-sdk-nodejs
1个回答
0
投票

你一开始很好,但需要做一些调整:

  const input = { // PublishInput
      PhoneNumber: "+16045181234",
      Message: "test message", // required
      Origination: "+12065551234" // <------- Add your PinPoint origination number
    };

      const client = new SNSClient({credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
        },region: 'us-east-1' // <---- Add your region, 
        });

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.