Using aws-sdk
v2 previously works fine before.
I’m trying to use the v3 now and somehow, I get a good response but sms is never received. I wonder if there’s some settings I’m missing here.
Here are the steps I took approach.
- Created a new policy just to publish sns
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
-
The user is attached to the policy, then created
access token
+secret access token
for the user. -
Created code.
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');
}
}
- Getting the response
{
'$metadata': {
httpStatusCode: 200,
requestId: '6c3f80ea-3ff2-5c38-bda6-dd6e27661c74',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
MessageId: 'a94988b1-ba63-5f5b-a647-d535a2f78f17'
}
But not getting any messages on mobile at all and no error thrown too.
Thank you in advance for any suggestions or advices.