Ahsan Chaudhary
Ahsan Chaudhary

Reputation: 1

Send AWS SNS push notifications from Canada region (ca-central-1)

I am using AWS services for my project which is hosted in Canada region (Ca-Central-1). Now I want to send SNS Push Notifications but came to know that SNS push notification is not available in this region. Can someone guide me on what is the way around? Plus I can't change the server from Canada to others.

Upvotes: 0

Views: 502

Answers (1)

Maurice
Maurice

Reputation: 13197

You can create an SNS topic in another region and use that one.

Since you're currently in ca-central-1 your SDK will think that you want to talk to SNS in that region. As a result of that you need to tell it explicitly to talk to SNS in another region if you want to send a message to that topic.

You can do that in two ways - I'm using the python SDK here, it's also possible in others. This is based on the assumption that your secondary region is eu-central-1.

import boto3

cross_region_client = boto3.client("sns", region_name="eu-central-1")

# Now you can use this to publish a message
cross_region_client.publish_message("...")

# The other option is to hardcode the endpoint url, but I'd prefer the former
cross_region_client = boto3.client("sns", endpoint_url="sns.eu-central-1.amazonaws.com")


Update: For JS

I'm going to adapt some code from the official AWS intro to the JS SDK:

const SnsClient = require("@aws-sdk/client-sns");

// Set the AWS region
const REGION = "REGION"; // e.g., "us-east-1"

// Create an SNS client service object
const sns= new SNSClient({ region: REGION });

Upvotes: 1

Related Questions