# AWS SNS Event

> AWS SNS event with message records, topic ARN, and message attributes.

- Name: `aws-sns-event`
- Categories: aws
- Detail page: https://open-types.dev/types/aws-sns-event

## Install

```bash
# Types only
npx shadcn add @open-types/aws-sns-event

# Types + Zod v4 validators
npx shadcn add @open-types/aws-sns-event-zod

# Types + real-world examples
npx shadcn add @open-types/aws-sns-event-examples
```

## Types

```typescript
export interface AWSSNSMessageAttribute {
  Type: string;
  Value: string;
}

export interface AWSSNSMessage {
  Type: string;
  MessageId: string;
  TopicArn: string;
  Subject: string | null;
  Message: string;
  Timestamp: string;
  SignatureVersion: string;
  Signature: string;
  SigningCertUrl: string;
  UnsubscribeUrl: string;
  MessageAttributes: Record<string, AWSSNSMessageAttribute>;
}

export interface AWSSNSEventRecord {
  EventVersion: string;
  EventSubscriptionArn: string;
  EventSource: string;
  Sns: AWSSNSMessage;
}

export interface AWSSNSEvent {
  Records: AWSSNSEventRecord[];
}
```

## Zod validator

```typescript
import * as z from "zod";
import type {
  AWSSNSMessageAttribute,
  AWSSNSMessage,
  AWSSNSEventRecord,
  AWSSNSEvent,
} from "../types/aws-sns-event";

export const awsSnsMessageAttributeSchema = z.object({
  Type: z.string(),
  Value: z.string(),
}) satisfies z.ZodType<AWSSNSMessageAttribute>;

export const awsSnsMessageSchema = z.object({
  Type: z.string(),
  MessageId: z.string(),
  TopicArn: z.string(),
  Subject: z.string().nullable(),
  Message: z.string(),
  Timestamp: z.string(),
  SignatureVersion: z.string(),
  Signature: z.string(),
  SigningCertUrl: z.string(),
  UnsubscribeUrl: z.string(),
  MessageAttributes: z.record(z.string(), awsSnsMessageAttributeSchema),
}) satisfies z.ZodType<AWSSNSMessage>;

export const awsSnsEventRecordSchema = z.object({
  EventVersion: z.string(),
  EventSubscriptionArn: z.string(),
  EventSource: z.string(),
  Sns: awsSnsMessageSchema,
}) satisfies z.ZodType<AWSSNSEventRecord>;

export const awsSnsEventSchema = z.object({
  Records: z.array(awsSnsEventRecordSchema),
}) satisfies z.ZodType<AWSSNSEvent>;

export type {
  AWSSNSMessageAttribute,
  AWSSNSMessage,
  AWSSNSEventRecord,
  AWSSNSEvent,
} from "../types/aws-sns-event";
```

## Examples

```typescript
// Source: https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html#with-sns-create-test-function
// Captured: 2026-05
import type {
  AWSSNSMessageAttribute,
  AWSSNSMessage,
  AWSSNSEventRecord,
  AWSSNSEvent,
} from "../types/aws-sns-event";

const eventTypeAttr = {
  Type: "String",
  Value: "billing.invoice.created",
} as const satisfies AWSSNSMessageAttribute;

export const awsSnsMessageAttributeExamples = {
  string: eventTypeAttr,
  number: { Type: "Number", Value: "42" } satisfies AWSSNSMessageAttribute,
  arrayJson: {
    Type: "String.Array",
    Value: '["tag1","tag2"]',
  } satisfies AWSSNSMessageAttribute,
} as const;

const notification = {
  Type: "Notification",
  MessageId: "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
  TopicArn: "arn:aws:sns:us-east-1:123456789012:billing-events",
  Subject: "Invoice created",
  Message: '{"invoiceId":"inv_123","status":"created"}',
  Timestamp: "2026-04-13T18:45:00.000Z",
  SignatureVersion: "1",
  Signature: "EXAMPLElDMO3T0exampleSignature==",
  SigningCertUrl: "https://sns.us-east-1.amazonaws.com/SimpleNotificationService.pem",
  UnsubscribeUrl: "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789012:billing-events:sub-123",
  MessageAttributes: { eventType: eventTypeAttr },
} as const satisfies AWSSNSMessage;

export const awsSnsMessageExamples = {
  notification,
  noSubject: { ...notification, Subject: null } satisfies AWSSNSMessage,
  plainText: {
    ...notification,
    MessageId: "abcdef01-2345-6789-abcd-ef0123456789",
    Subject: "Welcome",
    Message: "Welcome to our service!",
    MessageAttributes: {},
  } satisfies AWSSNSMessage,
} as const;

const eventRecord = {
  EventVersion: "1.0",
  EventSubscriptionArn: "arn:aws:sns:us-east-1:123456789012:billing-events:2bcfbf39-05c3-41de-9991-61f12EXAMPLE",
  EventSource: "aws:sns",
  Sns: notification,
} as const satisfies AWSSNSEventRecord;

export const awsSnsEventRecordExamples = {
  notification: eventRecord,
  plainText: { ...eventRecord, Sns: awsSnsMessageExamples.plainText } satisfies AWSSNSEventRecord,
} as const;

export const awsSnsEventExamples = {
  single: { Records: [eventRecord] } satisfies AWSSNSEvent,
  batch: {
    Records: [eventRecord, awsSnsEventRecordExamples.plainText],
  } satisfies AWSSNSEvent,
} as const;
```
