Skip to content

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.

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),
});
// init
const createEndpoint = yield* SNS.CreatePlatformEndpoint(app);
const publishToEndpoint = yield* SNS.PublishToEndpoint(app);
// runtime
const endpoint = yield* createEndpoint({ Token: deviceToken });
yield* publishToEndpoint({
TargetArn: endpoint.EndpointArn!,
Message: "hello",
});