Providers / AWS SNS

Test AWS SNS SMS without sending real messages

otpmock emulates the AWS SNS Publish to a phone number API. In your test environment, the official @aws-sdk/client-sns SDK talks to otpmock instead of AWS SNS; your end-to-end tests read each code over HTTP.

Updated October 8, 2026Tested with the official @aws-sdk/client-sns SDK
Short answer

Set OTPMOCK_URL=https://api.otpmock.com in your test environment, point the AWS SNS client at it, and use your otpmock API key as the AWS SNS credential. Your application code doesn't change, and production keeps sending real SMS through AWS SNS.

Setup

Every AWS SDK supports a custom endpoint.

sms.js
import { SNSClient } from "@aws-sdk/client-sns";

export const sns = new SNSClient({
  region: process.env.AWS_REGION ?? "us-east-1",
  ...(process.env.OTPMOCK_URL && {
    endpoint: process.env.OTPMOCK_URL,
    credentials: { accessKeyId: process.env.OTPMOCK_API_KEY, secretAccessKey: "unused" },
  }),
});

Credentials. In the test environment, use your otpmock API key as the access key ID. The secret access key can be any value; otpmock reads the access key ID from the SigV4 Authorization header and does not verify the signature.

What otpmock emulates

EndpointWhat it does
POST / (Action=Publish, PhoneNumber, Message)awsQuery protocol, XML response with MessageId

Responses and errors follow AWS SNS's own format, so the SDK parses them as usual. Authentication failures and an exhausted monthly allowance also come back in AWS SNS's error shape.

Phone numbers

Send in E.164 (+15550142), as SNS expects.

Read the code in your tests

signup.spec.ts
const phone = otp.randomPhone();
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Send code" }).click(); // your app calls AWS SNS
const { code } = await otp.waitForCode(phone, { since });

The otp helper is a single file: get it from the docs. Full walkthroughs: Playwright, Cypress.

Good to know

FAQ

Does otpmock send real SMS through AWS SNS?

No. In the test environment your app's AWS SNS requests go to otpmock, which stores the message for 10 minutes and never contacts AWS SNS or any carrier. Production keeps using AWS SNS because otpmock is only enabled when OTPMOCK_URL is set.

Is the official @aws-sdk/client-sns SDK supported?

Yes. otpmock's AWS SNS endpoints are tested end to end with the official @aws-sdk/client-sns package for Node.js. Other languages work too if their AWS SNS client lets you change the API host.

Which AWS SNS APIs does otpmock support?

POST / (Action=Publish, PhoneNumber, Message) (awsQuery protocol, XML response with MessageId).

Test AWS SNS flows today

The free plan includes 100 messages a month. Using an AI coding assistant? Point it at otpmock.com/llms-full.txt.

Get a free API key

Other providers