AWS.SNS reference
AddPermission
Section titled “AddPermission”Source:
src/AWS/SNS/AddPermission.ts
Runtime binding for sns:AddPermission.
Bind this operation to a Topic inside a function runtime to grant
other AWS accounts access to topic actions by adding a labeled statement
to the topic’s access policy. The binding grants the host function
sns:AddPermission on the topic. Provide the AddPermissionHttp layer on
the Function to implement the binding.
AddPermission: Managing Topic Permissions
Section titled “AddPermission: Managing Topic Permissions”// init (provide SNS.AddPermissionHttp on the Function)const addPermission = yield* SNS.AddPermission(topic);
// runtimeyield* addPermission({ Label: "PartnerPublish", AWSAccountId: ["123456789012"], ActionName: ["Publish"],});CheckIfPhoneNumberIsOptedOut
Section titled “CheckIfPhoneNumberIsOptedOut”Source:
src/AWS/SNS/CheckIfPhoneNumberIsOptedOut.ts
Runtime binding for sns:CheckIfPhoneNumberIsOptedOut.
An account-scoped operation — reports whether SMS delivery to a phone
number is blocked because its owner opted out.
Provide the CheckIfPhoneNumberIsOptedOutHttp layer on the Function to implement the binding.
CheckIfPhoneNumberIsOptedOut: SMS Opt-Out Management
Section titled “CheckIfPhoneNumberIsOptedOut: SMS Opt-Out Management”const checkOptOut = yield* SNS.CheckIfPhoneNumberIsOptedOut();const { isOptedOut } = yield* checkOptOut({ phoneNumber: "+15555550123" });ConfirmSubscription
Section titled “ConfirmSubscription”Source:
src/AWS/SNS/ConfirmSubscription.ts
Runtime binding for sns:ConfirmSubscription.
Bind this operation to a Subscription inside a function runtime to
confirm a pending subscription with the token SNS delivered to the
endpoint (e.g. from an https or email confirmation message). The
binding grants the host function sns:ConfirmSubscription on the topic.
Provide the ConfirmSubscriptionHttp layer on the Function to implement
the binding.
ConfirmSubscription: Confirming Subscriptions
Section titled “ConfirmSubscription: Confirming Subscriptions”// init (provide SNS.ConfirmSubscriptionHttp on the Function)const confirmSubscription = yield* SNS.ConfirmSubscription(subscription);
// runtime: token comes from the SubscriptionConfirmation messageconst response = yield* confirmSubscription({ Token: token });// response.SubscriptionArnCreatePlatformEndpoint
Section titled “CreatePlatformEndpoint”Source:
src/AWS/SNS/CreatePlatformEndpoint.ts
Runtime binding for sns:CreatePlatformEndpoint.
Bind this operation to a PlatformApplication to register device
push tokens at runtime. The PlatformApplicationArn is injected
automatically; the call is idempotent per token.
Provide the CreatePlatformEndpointHttp layer on the Function to implement the binding.
CreatePlatformEndpoint: Mobile Push
Section titled “CreatePlatformEndpoint: Mobile Push”const createEndpoint = yield* SNS.CreatePlatformEndpoint(app);const endpoint = yield* createEndpoint({ Token: deviceToken });CreateSMSSandboxPhoneNumber
Section titled “CreateSMSSandboxPhoneNumber”Source:
src/AWS/SNS/CreateSMSSandboxPhoneNumber.ts
Runtime binding for sns:CreateSMSSandboxPhoneNumber.
An account-scoped operation — registers a destination phone number in
the SMS sandbox, which sends it a one-time verification code.
Provide the CreateSMSSandboxPhoneNumberHttp layer on the Function to implement the binding.
CreateSMSSandboxPhoneNumber: SMS Sandbox
Section titled “CreateSMSSandboxPhoneNumber: SMS Sandbox”const createSandboxNumber = yield* SNS.CreateSMSSandboxPhoneNumber();yield* createSandboxNumber({ PhoneNumber: "+15555550123" });DeleteEndpoint
Section titled “DeleteEndpoint”Source:
src/AWS/SNS/DeleteEndpoint.ts
Runtime binding for sns:DeleteEndpoint.
Bind this operation to a PlatformApplication to deregister one
of its device endpoints (idempotent).
Provide the DeleteEndpointHttp layer on the Function to implement the binding.
DeleteEndpoint: Mobile Push
Section titled “DeleteEndpoint: Mobile Push”const deleteEndpoint = yield* SNS.DeleteEndpoint(app);yield* deleteEndpoint({ EndpointArn: endpointArn });DeleteSMSSandboxPhoneNumber
Section titled “DeleteSMSSandboxPhoneNumber”Source:
src/AWS/SNS/DeleteSMSSandboxPhoneNumber.ts
Runtime binding for sns:DeleteSMSSandboxPhoneNumber.
An account-scoped operation — removes a destination phone number from
the account’s SMS sandbox.
Provide the DeleteSMSSandboxPhoneNumberHttp layer on the Function to implement the binding.
DeleteSMSSandboxPhoneNumber: SMS Sandbox
Section titled “DeleteSMSSandboxPhoneNumber: SMS Sandbox”const deleteSandboxNumber = yield* SNS.DeleteSMSSandboxPhoneNumber();yield* deleteSandboxNumber({ PhoneNumber: "+15555550123" });GetDataProtectionPolicy
Section titled “GetDataProtectionPolicy”Source:
src/AWS/SNS/GetDataProtectionPolicy.ts
Runtime binding for sns:GetDataProtectionPolicy.
Bind this operation to a Topic inside a function runtime to read
the topic’s data protection policy document; the ResourceArn is injected
automatically. The binding grants the host function
sns:GetDataProtectionPolicy on the topic. Provide the
GetDataProtectionPolicyHttp layer on the Function to implement the
binding.
GetDataProtectionPolicy: Data Protection Policies
Section titled “GetDataProtectionPolicy: Data Protection Policies”// init (provide SNS.GetDataProtectionPolicyHttp on the Function)const getDataProtectionPolicy = yield* SNS.GetDataProtectionPolicy(topic);
// runtimeconst response = yield* getDataProtectionPolicy();// response.DataProtectionPolicy (JSON document string)GetEndpointAttributes
Section titled “GetEndpointAttributes”Source:
src/AWS/SNS/GetEndpointAttributes.ts
Runtime binding for sns:GetEndpointAttributes.
Bind this operation to a PlatformApplication to read the
attributes (Token, Enabled, CustomUserData) of one of its device
endpoints.
Provide the GetEndpointAttributesHttp layer on the Function to implement the binding.
GetEndpointAttributes: Mobile Push
Section titled “GetEndpointAttributes: Mobile Push”const getEndpointAttributes = yield* SNS.GetEndpointAttributes(app);const { Attributes } = yield* getEndpointAttributes({ EndpointArn: endpointArn,});GetSMSAttributes
Section titled “GetSMSAttributes”Source:
src/AWS/SNS/GetSMSAttributes.ts
Runtime binding for sns:GetSMSAttributes.
An account-scoped operation — reads the account-level SMS settings such
as DefaultSMSType, MonthlySpendLimit, and delivery-status sampling.
Provide the GetSMSAttributesHttp layer on the Function to implement the binding.
GetSMSAttributes: SMS Account Settings
Section titled “GetSMSAttributes: SMS Account Settings”const getSmsAttributes = yield* SNS.GetSMSAttributes();const { attributes } = yield* getSmsAttributes();GetSMSSandboxAccountStatus
Section titled “GetSMSSandboxAccountStatus”Source:
src/AWS/SNS/GetSMSSandboxAccountStatus.ts
Runtime binding for sns:GetSMSSandboxAccountStatus.
An account-scoped operation — reports whether the account is still in
the SMS sandbox (only verified destination numbers deliverable).
Provide the GetSMSSandboxAccountStatusHttp layer on the Function to implement the binding.
GetSMSSandboxAccountStatus: SMS Sandbox
Section titled “GetSMSSandboxAccountStatus: SMS Sandbox”const getSandboxStatus = yield* SNS.GetSMSSandboxAccountStatus();const { IsInSandbox } = yield* getSandboxStatus();GetSubscriptionAttributes
Section titled “GetSubscriptionAttributes”Source:
src/AWS/SNS/GetSubscriptionAttributes.ts
Runtime binding for sns:GetSubscriptionAttributes.
Bind this operation to a Subscription inside a function runtime to
read the subscription’s raw attribute map (filter policy, redrive policy,
raw message delivery, etc.). The binding grants the host function
sns:GetSubscriptionAttributes on the subscription. Provide the
GetSubscriptionAttributesHttp layer on the Function to implement the
binding.
GetSubscriptionAttributes: Reading Subscription Attributes
Section titled “GetSubscriptionAttributes: Reading Subscription Attributes”// init (provide SNS.GetSubscriptionAttributesHttp on the Function)const getSubscriptionAttributes = yield* SNS.GetSubscriptionAttributes(subscription);
// runtimeconst response = yield* getSubscriptionAttributes();const filterPolicy = response.Attributes?.FilterPolicy;GetTopicAttributes
Section titled “GetTopicAttributes”Source:
src/AWS/SNS/GetTopicAttributes.ts
Runtime binding for sns:GetTopicAttributes.
Bind this operation to a Topic inside a function runtime to read
the topic’s raw attribute map (policy, delivery status, KMS key, etc.).
The binding grants the host function sns:GetTopicAttributes on the
topic. Provide the GetTopicAttributesHttp layer on the Function to
implement the binding.
GetTopicAttributes: Reading Topic Attributes
Section titled “GetTopicAttributes: Reading Topic Attributes”// init (provide SNS.GetTopicAttributesHttp on the Function)const getTopicAttributes = yield* SNS.GetTopicAttributes(topic);
// runtimeconst response = yield* getTopicAttributes();const displayName = response.Attributes?.DisplayName;ListEndpointsByPlatformApplication
Section titled “ListEndpointsByPlatformApplication”Source:
src/AWS/SNS/ListEndpointsByPlatformApplication.ts
Runtime binding for sns:ListEndpointsByPlatformApplication.
Bind this operation to a PlatformApplication to page through its
registered device endpoints.
Provide the ListEndpointsByPlatformApplicationHttp layer on the Function to implement the binding.
ListEndpointsByPlatformApplication: Mobile Push
Section titled “ListEndpointsByPlatformApplication: Mobile Push”const listEndpoints = yield* SNS.ListEndpointsByPlatformApplication(app);const { Endpoints } = yield* listEndpoints();ListOriginationNumbers
Section titled “ListOriginationNumbers”Source:
src/AWS/SNS/ListOriginationNumbers.ts
Runtime binding for sns:ListOriginationNumbers.
An account-scoped operation — lists the origination phone numbers
available to send SMS from this account.
Provide the ListOriginationNumbersHttp layer on the Function to implement the binding.
ListOriginationNumbers: SMS Account Settings
Section titled “ListOriginationNumbers: SMS Account Settings”const listOriginationNumbers = yield* SNS.ListOriginationNumbers();const { PhoneNumbers } = yield* listOriginationNumbers();ListPhoneNumbersOptedOut
Section titled “ListPhoneNumbersOptedOut”Source:
src/AWS/SNS/ListPhoneNumbersOptedOut.ts
Runtime binding for sns:ListPhoneNumbersOptedOut.
An account-scoped operation — pages through the phone numbers whose
owners opted out of receiving SMS from this account.
Provide the ListPhoneNumbersOptedOutHttp layer on the Function to implement the binding.
ListPhoneNumbersOptedOut: SMS Opt-Out Management
Section titled “ListPhoneNumbersOptedOut: SMS Opt-Out Management”const listOptedOut = yield* SNS.ListPhoneNumbersOptedOut();const { phoneNumbers } = yield* listOptedOut();ListPlatformApplications
Section titled “ListPlatformApplications”Source:
src/AWS/SNS/ListPlatformApplications.ts
Runtime binding for sns:ListPlatformApplications.
An account-scoped operation — pages through the mobile-push platform
applications in the account/region.
Provide the ListPlatformApplicationsHttp layer on the Function to implement the binding.
ListPlatformApplications: Mobile Push
Section titled “ListPlatformApplications: Mobile Push”const listApplications = yield* SNS.ListPlatformApplications();const { PlatformApplications } = yield* listApplications();ListSMSSandboxPhoneNumbers
Section titled “ListSMSSandboxPhoneNumbers”Source:
src/AWS/SNS/ListSMSSandboxPhoneNumbers.ts
Runtime binding for sns:ListSMSSandboxPhoneNumbers.
An account-scoped operation — lists the destination phone numbers
registered (verified or pending) in the account’s SMS sandbox.
Provide the ListSMSSandboxPhoneNumbersHttp layer on the Function to implement the binding.
ListSMSSandboxPhoneNumbers: SMS Sandbox
Section titled “ListSMSSandboxPhoneNumbers: SMS Sandbox”const listSandboxNumbers = yield* SNS.ListSMSSandboxPhoneNumbers();const { PhoneNumbers } = yield* listSandboxNumbers();ListSubscriptions
Section titled “ListSubscriptions”Source:
src/AWS/SNS/ListSubscriptions.ts
Runtime binding for sns:ListSubscriptions.
An account-scoped operation — bind it with no arguments to page through
all subscriptions in the account/region. The binding grants the host
function sns:ListSubscriptions. Provide the ListSubscriptionsHttp
layer on the Function to implement the binding.
To list only the subscriptions of one topic, use
ListSubscriptionsByTopic.
ListSubscriptions: Listing Subscriptions
Section titled “ListSubscriptions: Listing Subscriptions”// init (provide SNS.ListSubscriptionsHttp on the Function)const listSubscriptions = yield* SNS.ListSubscriptions();
// runtime: pass NextToken to page through large accountsconst response = yield* listSubscriptions();// response.SubscriptionsListSubscriptionsByTopic
Section titled “ListSubscriptionsByTopic”Source:
src/AWS/SNS/ListSubscriptionsByTopic.ts
Runtime binding for sns:ListSubscriptionsByTopic.
Bind this operation to a Topic inside a function runtime to page
through that topic’s subscriptions; the TopicArn is injected
automatically. The binding grants the host function
sns:ListSubscriptionsByTopic on the topic. Provide the
ListSubscriptionsByTopicHttp layer on the Function to implement the
binding.
ListSubscriptionsByTopic: Listing a Topic’s Subscriptions
Section titled “ListSubscriptionsByTopic: Listing a Topic’s Subscriptions”// init (provide SNS.ListSubscriptionsByTopicHttp on the Function)const listSubscriptionsByTopic = yield* SNS.ListSubscriptionsByTopic(topic);
// runtimeconst response = yield* listSubscriptionsByTopic();const endpoints = (response.Subscriptions ?? []).map((s) => s.Endpoint);ListTagsForResource
Section titled “ListTagsForResource”Source:
src/AWS/SNS/ListTagsForResource.ts
Runtime binding for sns:ListTagsForResource.
Bind this operation to a Topic inside a function runtime to read
the topic’s tags; the ResourceArn is injected automatically. The binding
grants the host function sns:ListTagsForResource on the topic. Provide
the ListTagsForResourceHttp layer on the Function to implement the
binding.
ListTagsForResource: Tagging Topics
Section titled “ListTagsForResource: Tagging Topics”// init (provide SNS.ListTagsForResourceHttp on the Function)const listTagsForResource = yield* SNS.ListTagsForResource(topic);
// runtimeconst response = yield* listTagsForResource();// response.TagsListTopics
Section titled “ListTopics”Source:
src/AWS/SNS/ListTopics.ts
Runtime binding for sns:ListTopics.
An account-scoped operation — bind it with no arguments to page through
all topic ARNs in the account/region. The binding grants the host function
sns:ListTopics. Provide the ListTopicsHttp layer on the Function to
implement the binding.
ListTopics: Listing Topics
Section titled “ListTopics: Listing Topics”// init (provide SNS.ListTopicsHttp on the Function)const listTopics = yield* SNS.ListTopics();
// runtime: pass NextToken to page through large accountsconst response = yield* listTopics();const arns = (response.Topics ?? []).map((topic) => topic.TopicArn);OptInPhoneNumber
Section titled “OptInPhoneNumber”Source:
src/AWS/SNS/OptInPhoneNumber.ts
Runtime binding for sns:OptInPhoneNumber.
An account-scoped operation — opts a previously opted-out phone number
back in to SMS delivery (allowed once every 30 days per number).
Provide the OptInPhoneNumberHttp layer on the Function to implement the binding.
OptInPhoneNumber: SMS Opt-Out Management
Section titled “OptInPhoneNumber: SMS Opt-Out Management”const optIn = yield* SNS.OptInPhoneNumber();yield* optIn({ phoneNumber: "+15555550123" });PlatformApplication
Section titled “PlatformApplication”Source:
src/AWS/SNS/PlatformApplication.ts
An Amazon SNS platform application for mobile push notifications (FCM, APNS, ADM, Baidu).
A platform application holds the push service credentials; device tokens
are registered against it at runtime with the
CreatePlatformEndpoint binding, and messages are delivered with
PublishToEndpoint. SNS validates the credential when the application is
created, so a real push-service credential is required.
PlatformApplication: Creating Platform Applications
Section titled “PlatformApplication: Creating Platform Applications”FCM (GCM) Application
import * as SNS from "alchemy/AWS/SNS";import * as Redacted from "effect/Redacted";
const app = yield* SNS.PlatformApplication("PushApp", { platform: "GCM", platformCredential: Redacted.make(process.env.FCM_API_KEY!),});APNS Application
const app = yield* SNS.PlatformApplication("IosPushApp", { platform: "APNS", platformCredential: Redacted.make(apnsPrivateKey), platformPrincipal: Redacted.make(apnsCertificate),});PlatformApplication: Runtime Endpoints
Section titled “PlatformApplication: Runtime Endpoints”// initconst createEndpoint = yield* SNS.CreatePlatformEndpoint(app);const publishToEndpoint = yield* SNS.PublishToEndpoint(app);
// runtimeconst endpoint = yield* createEndpoint({ Token: deviceToken });yield* publishToEndpoint({ TargetArn: endpoint.EndpointArn!, Message: "hello",});Publish
Section titled “Publish”Source:
src/AWS/SNS/Publish.ts
Runtime binding for sns:Publish.
Bind this operation to a Topic inside a function runtime to get a
callable that automatically injects the TopicArn. The binding grants the
host function sns:Publish on the topic. Provide the PublishHttp layer
on the Function to implement the binding.
Publish: Publishing Messages
Section titled “Publish: Publishing Messages”export class ApiFunction extends Lambda.Function<Lambda.Function>()( "ApiFunction",) {}
export default ApiFunction.make( { main: import.meta.url, functionUrl: true }, Effect.gen(function* () { const topic = yield* SNS.Topic("Events");
// init: bind the operation to the topic (grants sns:Publish) const publish = yield* SNS.Publish(topic);
return { fetch: Effect.gen(function* () { // runtime: TopicArn is injected automatically const response = yield* publish({ Message: "order shipped", Subject: "order-update", }); return yield* HttpServerResponse.json({ messageId: response.MessageId, }); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(SNS.PublishHttp)),);PublishBatch
Section titled “PublishBatch”Source:
src/AWS/SNS/PublishBatch.ts
Runtime binding for sns:PublishBatch.
Bind this operation to a Topic inside a function runtime to publish
up to 10 messages per call with per-entry success/failure results. The
binding grants the host function sns:Publish on the topic. Provide the
PublishBatchHttp layer on the Function to implement the binding.
For an unbounded stream of messages with automatic batching and bounded
retry of transient per-entry failures, prefer TopicSink.
PublishBatch: Publishing Message Batches
Section titled “PublishBatch: Publishing Message Batches”// init (provide SNS.PublishBatchHttp on the Function)const publishBatch = yield* SNS.PublishBatch(topic);
// runtimeconst response = yield* publishBatch({ PublishBatchRequestEntries: messages.map((message, index) => ({ Id: `${index}`, Message: message, })),});// response.Successful / response.FailedPublishSms
Section titled “PublishSms”Source:
src/AWS/SNS/PublishSms.ts
Runtime binding for sns:Publish.
Runtime binding for direct SMS delivery with sns:Publish — send a text
message straight to a phone number without a topic. Accounts start in the
SMS sandbox, where only verified destination numbers are deliverable.
Provide the PublishSmsHttp layer on the Function to implement the binding.
PublishSms: Sending SMS
Section titled “PublishSms: Sending SMS”const publishSms = yield* SNS.PublishSms();yield* publishSms({ PhoneNumber: "+15555550123", Message: "Your code is 123456",});PublishToEndpoint
Section titled “PublishToEndpoint”Source:
src/AWS/SNS/PublishToEndpoint.ts
Runtime binding for sns:Publish.
Runtime binding for sns:Publish targeting a mobile-push endpoint of a
PlatformApplication: pass the device TargetArn returned by
CreatePlatformEndpoint.
Provide the PublishToEndpointHttp layer on the Function to implement the binding.
PublishToEndpoint: Mobile Push
Section titled “PublishToEndpoint: Mobile Push”const publishToEndpoint = yield* SNS.PublishToEndpoint(app);yield* publishToEndpoint({ TargetArn: endpointArn, Message: "hello",});PutDataProtectionPolicy
Section titled “PutDataProtectionPolicy”Source:
src/AWS/SNS/PutDataProtectionPolicy.ts
Runtime binding for sns:PutDataProtectionPolicy.
Bind this operation to a Topic inside a function runtime to attach
or replace the topic’s data protection policy; the ResourceArn is
injected automatically. The binding grants the host function
sns:PutDataProtectionPolicy on the topic. Provide the
PutDataProtectionPolicyHttp layer on the Function to implement the
binding.
PutDataProtectionPolicy: Data Protection Policies
Section titled “PutDataProtectionPolicy: Data Protection Policies”// init (provide SNS.PutDataProtectionPolicyHttp on the Function)const putDataProtectionPolicy = yield* SNS.PutDataProtectionPolicy(topic);
// runtimeyield* putDataProtectionPolicy({ DataProtectionPolicy: JSON.stringify({ Name: "basic-pii-audit", Version: "2021-06-01", Statement: [], }),});RemovePermission
Section titled “RemovePermission”Source:
src/AWS/SNS/RemovePermission.ts
Runtime binding for sns:RemovePermission.
Bind this operation to a Topic inside a function runtime to remove
a policy statement previously added with AddPermission by its
label. The binding grants the host function sns:RemovePermission on the
topic. Provide the RemovePermissionHttp layer on the Function to
implement the binding.
RemovePermission: Managing Topic Permissions
Section titled “RemovePermission: Managing Topic Permissions”// init (provide SNS.RemovePermissionHttp on the Function)const removePermission = yield* SNS.RemovePermission(topic);
// runtimeyield* removePermission({ Label: "PartnerPublish" });SetEndpointAttributes
Section titled “SetEndpointAttributes”Source:
src/AWS/SNS/SetEndpointAttributes.ts
Runtime binding for sns:SetEndpointAttributes.
Bind this operation to a PlatformApplication to update a device
endpoint — e.g. re-enable it after a delivery failure or rotate its token.
Provide the SetEndpointAttributesHttp layer on the Function to implement the binding.
SetEndpointAttributes: Mobile Push
Section titled “SetEndpointAttributes: Mobile Push”const setEndpointAttributes = yield* SNS.SetEndpointAttributes(app);yield* setEndpointAttributes({ EndpointArn: endpointArn, Attributes: { Enabled: "true" },});SetSMSAttributes
Section titled “SetSMSAttributes”Source:
src/AWS/SNS/SetSMSAttributes.ts
Runtime binding for sns:SetSMSAttributes.
An account-scoped operation — updates the account-level SMS settings,
e.g. switching the default message type between Promotional and
Transactional.
Provide the SetSMSAttributesHttp layer on the Function to implement the binding.
SetSMSAttributes: SMS Account Settings
Section titled “SetSMSAttributes: SMS Account Settings”const setSmsAttributes = yield* SNS.SetSMSAttributes();yield* setSmsAttributes({ attributes: { DefaultSMSType: "Transactional" },});SetSubscriptionAttributes
Section titled “SetSubscriptionAttributes”Source:
src/AWS/SNS/SetSubscriptionAttributes.ts
Runtime binding for sns:SetSubscriptionAttributes.
Bind this operation to a Subscription inside a function runtime to
set a single subscription attribute by name (e.g. FilterPolicy,
RawMessageDelivery). The binding grants the host function
sns:SetSubscriptionAttributes on the subscription. Provide the
SetSubscriptionAttributesHttp layer on the Function to implement the
binding.
SetSubscriptionAttributes: Updating Subscription Attributes
Section titled “SetSubscriptionAttributes: Updating Subscription Attributes”// init (provide SNS.SetSubscriptionAttributesHttp on the Function)const setSubscriptionAttributes = yield* SNS.SetSubscriptionAttributes(subscription);
// runtimeyield* setSubscriptionAttributes({ AttributeName: "FilterPolicy", AttributeValue: JSON.stringify({ type: ["order"] }),});SetTopicAttributes
Section titled “SetTopicAttributes”Source:
src/AWS/SNS/SetTopicAttributes.ts
Runtime binding for sns:SetTopicAttributes.
Bind this operation to a Topic inside a function runtime to set a
single topic attribute by name. The binding grants the host function
sns:SetTopicAttributes on the topic. Provide the
SetTopicAttributesHttp layer on the Function to implement the binding.
SetTopicAttributes: Updating Topic Attributes
Section titled “SetTopicAttributes: Updating Topic Attributes”// init (provide SNS.SetTopicAttributesHttp on the Function)const setTopicAttributes = yield* SNS.SetTopicAttributes(topic);
// runtimeyield* setTopicAttributes({ AttributeName: "DisplayName", AttributeValue: "order-events",});Subscribe
Section titled “Subscribe”Source:
src/AWS/SNS/Subscribe.ts
Runtime binding for sns:Subscribe.
Bind this operation to a Topic to subscribe endpoints (email,
sms, https, sqs, …) to the topic at runtime — for example subscribing a
user’s email address from an API handler. The TopicArn is injected
automatically.
Provide the SubscribeHttp layer on the Function to implement the binding.
Subscribe: Subscribing Endpoints
Section titled “Subscribe: Subscribing Endpoints”const subscribe = yield* SNS.Subscribe(topic);const response = yield* subscribe({ Protocol: "email", Endpoint: "user@example.com",});Subscription
Section titled “Subscription”Source:
src/AWS/SNS/Subscription.ts
An Amazon SNS subscription that attaches an endpoint to a topic.
Subscription keeps the lifecycle of the subscription itself separate from the
topic, which lets Lambda event sources and manually managed subscriptions share
the same canonical resource model.
Subscription: Creating Subscriptions
Section titled “Subscription: Creating Subscriptions”Lambda Subscription
const subscription = yield* Subscription("TopicSubscription", { topicArn: topic.topicArn, protocol: "lambda", endpoint: fn.functionArn,});Fan Out a Topic to an SQS Queue
const topic = yield* SNS.Topic("Events");const queue = yield* SQS.Queue("Notifications");
const subscription = yield* Subscription("QueueSubscription", { topicArn: topic.topicArn, protocol: "sqs", endpoint: queue.queueArn, returnSubscriptionArn: true,});Filtered Subscription
const subscription = yield* Subscription("OrderSubscription", { topicArn: topic.topicArn, protocol: "sqs", endpoint: queue.queueArn, attributes: { FilterPolicy: JSON.stringify({ type: ["order"] }), },});TagResource
Section titled “TagResource”Source:
src/AWS/SNS/TagResource.ts
Runtime binding for sns:TagResource.
Bind this operation to a Topic inside a function runtime to add or
overwrite tags on the topic; the ResourceArn is injected automatically.
The binding grants the host function sns:TagResource on the topic.
Provide the TagResourceHttp layer on the Function to implement the
binding.
TagResource: Tagging Topics
Section titled “TagResource: Tagging Topics”// init (provide SNS.TagResourceHttp on the Function)const tagResource = yield* SNS.TagResource(topic);
// runtimeyield* tagResource({ Tags: [{ Key: "team", Value: "orders" }],});Source:
src/AWS/SNS/Topic.ts
An Amazon SNS topic for fan-out messaging and notifications.
Topic owns the SNS topic lifecycle while raw AWS topic attributes remain
available through the attributes prop so the full core pub/sub surface can
be configured without waiting on additional typed wrappers. A topic name is
auto-generated unless you provide one explicitly.
Topic: Creating Topics
Section titled “Topic: Creating Topics”Standard Topic
import * as SNS from "alchemy/AWS/SNS";
const topic = yield* SNS.Topic("OrdersTopic");Topic with Display Name
const topic = yield* SNS.Topic("NotificationsTopic", { attributes: { DisplayName: "App Notifications", },});FIFO Topic
const topic = yield* SNS.Topic("OrdersFifoTopic", { fifo: true, attributes: { ContentBasedDeduplication: "true", },});Topic: Runtime Publishing
Section titled “Topic: Runtime Publishing”Bind publish operations in the init phase and use them in runtime handlers.
// initconst publish = yield* SNS.Publish(topic);
return { fetch: Effect.gen(function* () { // runtime yield* publish({ Message: JSON.stringify({ orderId: "123" }), Subject: "OrderCreated", }); return HttpServerResponse.text("Published"); }),};Topic: Subscriptions
Section titled “Topic: Subscriptions”Subscribe a Lambda function to process messages published to the topic. The subscription and invoke permissions are created automatically.
// inityield* SNS.consumeTopicNotifications(topic, (stream) => stream.pipe( Stream.runForEach((message) => Effect.log(`Received: ${message.Message}`), ), ),);TopicEventSource
Section titled “TopicEventSource”Source:
src/AWS/SNS/TopicEventSource.ts
Event source connecting an SNS Topic to the hosting Lambda
function: it creates the lambda-protocol subscription (plus the invoke
permission) at deploy time and dispatches delivered notifications to the
registered handler at runtime.
The contract is a Binding.Service; the Lambda implementation layer is
Lambda.TopicEventSource. Consume it through the
consumeTopicNotifications helper.
TopicEventSource: Consuming a Topic
Section titled “TopicEventSource: Consuming a Topic”export default WorkerFunction.make( { main: import.meta.url }, Effect.gen(function* () { const topic = yield* SNS.Topic("Events");
// registers the subscription and the runtime dispatcher yield* SNS.consumeTopicNotifications(topic, (stream) => stream.pipe( Stream.runForEach((message) => Effect.log(message.Message)), ), ); }).pipe(Effect.provide(Lambda.TopicEventSource)),);TopicSink
Section titled “TopicSink”Source:
src/AWS/SNS/TopicSink.ts
A batching sink over SNS PublishBatch (10 entries / 256 KiB per call).
Per-entry failures with SenderFault: false (throttling, internal errors)
are retried on a bounded schedule; SenderFault: true failures are
permanent and dropped. Exhausting retries fails the sink with a typed
BatchRetryExhaustedError carrying the stranded entries.
The binding grants the host function sns:Publish on the topic. Provide
the TopicSinkHttp layer (which itself needs PublishBatchHttp) on the
Function to implement the binding.
TopicSink: Streaming Messages into a Topic
Section titled “TopicSink: Streaming Messages into a Topic”// init (provide SNS.TopicSinkHttp + SNS.PublishBatchHttp on the Function)const sink = yield* SNS.TopicSink(topic);
// runtime: batching, size limits, and transient-failure retry are handled// by the sink — each element is a PublishBatchRequestEntry minus `Id`.yield* Stream.fromIterable(messages).pipe( Stream.map((message) => ({ Message: message })), Stream.run(sink),);Unsubscribe
Section titled “Unsubscribe”Source:
src/AWS/SNS/Unsubscribe.ts
Runtime binding for sns:Unsubscribe.
An account-scoped operation — deletes a subscription by ARN, e.g. one
created at runtime with the Subscribe binding.
Provide the UnsubscribeHttp layer on the Function to implement the binding.
Unsubscribe: Unsubscribing
Section titled “Unsubscribe: Unsubscribing”const unsubscribe = yield* SNS.Unsubscribe();yield* unsubscribe({ SubscriptionArn: subscriptionArn });UntagResource
Section titled “UntagResource”Source:
src/AWS/SNS/UntagResource.ts
Runtime binding for sns:UntagResource.
Bind this operation to a Topic inside a function runtime to remove
tags from the topic by key; the ResourceArn is injected automatically.
The binding grants the host function sns:UntagResource on the topic.
Provide the UntagResourceHttp layer on the Function to implement the
binding.
UntagResource: Tagging Topics
Section titled “UntagResource: Tagging Topics”// init (provide SNS.UntagResourceHttp on the Function)const untagResource = yield* SNS.UntagResource(topic);
// runtimeyield* untagResource({ TagKeys: ["team"] });VerifySMSSandboxPhoneNumber
Section titled “VerifySMSSandboxPhoneNumber”Source:
src/AWS/SNS/VerifySMSSandboxPhoneNumber.ts
Runtime binding for sns:VerifySMSSandboxPhoneNumber.
An account-scoped operation — verifies a sandbox destination phone
number with the one-time password SNS texted to it.
Provide the VerifySMSSandboxPhoneNumberHttp layer on the Function to implement the binding.
VerifySMSSandboxPhoneNumber: SMS Sandbox
Section titled “VerifySMSSandboxPhoneNumber: SMS Sandbox”const verifySandboxNumber = yield* SNS.VerifySMSSandboxPhoneNumber();yield* verifySandboxNumber({ PhoneNumber: "+15555550123", OneTimePassword: "123456",});