使用
aws-sdk
v2 以前工作得很好。
我现在尝试使用 v3,不知怎的,我得到了很好的回应,但从未收到短信。我想知道我是否缺少一些设置。
以下是我采取的步骤。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
用户已附加到策略,然后为用户创建
access token
+ secret access token
。
已创建代码。
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');
}
}
{
'$metadata': {
httpStatusCode: 200,
requestId: '6c3f80ea-3ff2-5c38-bda6-dd6e27661c74',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
MessageId: 'a94988b1-ba63-5f5b-a647-d535a2f78f17'
}
但在移动设备上根本没有收到任何消息,也没有抛出任何错误。
提前感谢您的任何建议或意见。
你一开始很好,但需要做一些调整:
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,
});