Set up a SQS queue to receive notifications from an SNS topic located in another AWS account by using AWS CDK in TypeScript

Looking to establish a connection between an SQS queue and an SNS topic located in a different account using CDK (TypeScript). Presented below is the code snippet (contained within a stack) that I believe should facilitate this integration. However, I have a few concerns highlighted beneath the code (I haven't deployed this yet as I'm still exploring the process).

    const topic = Topic.fromTopicArn(
      this,
      `${stackName}-topic`,
      `arn:aws:sns:${region}:${accountno}:SubscriptionChanges`
    );

    topic.addSubscription(
      new SqsSubscription(queue, {
        filterPolicy: {
          type: SubscriptionFilter.stringFilter({
            whitelist: [
              'filter1',
            ],
          })
        },
      })
    );
  }
  • Is it permissible to use fromTopicArn to instantiate the topic construct when I am not the owner of the topic (since the topic exists in a different account requiring cross-account setup)?
  • Can a SQS subscription be created without declaring the topic variable as shown in the first line above?

Reviewing the official documentation, I observed code examples demonstrating similar setups but limited to interactions within the same AWS account. Seeking insights from individuals with practical experience regarding this scenario.

Answer №1

After conducting thorough research, I have gathered some valuable information.

It is possible to create a topic construct even without owning the topic, and you can link a queue to it. However, access must be granted by the topic owner (specifically, your account number).

const queue = createQueue();
const topic = sns.Topic.fromTopicArn(
  this, // assuming `this` refers to your Deployment Stack object.
  "myTopicId",
  "arn:aws:sns:eu-west-1:123123123123:MyFriendsGreatSnsTopic");

topic.addSubscription(new snsSubs.SqsSubscription(queue, {
   rawMessageDelivery: true // set to false if desired
}));

Answer №2

Below is a method to assign topic ownership for accessing an account

        Use the code snippet below to grant permission for subscribing to a topic:
        topic.addToResourcePolicy(new PolicyStatement({
            sid: "Allow Access to subscribe",
            effect: Effect.ALLOW,
            principals: [new AccountPrincipal(<***>)],
            actions: [
                "SNS:Subscribe"
            ],
            resources: [
                topic.topicArn
            ]
        }))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying Gmail line breaks in the clipboard using Angular

I'm currently working on a feature that allows users to paste content from Gmail into a field and detect line breaks. The field doesn't have to be a text area, I just need to identify the line breaks. However, there seems to be an issue with det ...

What is the significance of `/// <reference types="react-scripts" />` in programming? Are there any other XML-like syntaxes that are commonly used in *.d.ts

When working with normal *.d.ts files (which are definition files for TypeScript), we typically use declare *** export interface *** However, there is also this syntax: /// <reference types="react-scripts" /> This syntax is generated by create- ...

The function does not yield any result

import { Injectable } from '@angular/core'; export class Test { public id: number; public name: string; public fid: number }; export const TESTS2: Test[] = [ {id: 1, name: 'Lion', fid: 1}, {id: 2, name: 'Tiger', fid: 1 ...

When using TypeScript and React with Babel, an error may occur: "ReferenceError: The variable 'regeneratorRuntime'

I've been delving into learning typescript, react, and babel, and here is the code I've come up with: export default function App(): JSX.Element { console.log('+++++ came inside App +++++++ '); const {state, dispatch} = useCont ...

Step-by-step guide on incorporating an external JavaScript library into an Ionic 3 TypeScript project

As part of a project, I am tasked with creating a custom thermostat app. While I initially wanted to use Ionic for this task, I encountered some difficulty in integrating the provided API into my project. The API.js file contains all the necessary function ...

Having trouble showing JSON data with Ionic 2 and Xcode?

Extracting JSON data from a JSON file in my project and viewing it using "ionic serve" on my Mac has been successful. However, I am facing an issue after building for IOS in XCode. I import the generated project into XCode as usual, but the JSON data is no ...

Efficient access to variable-enumerated objects in TypeScript

Let's say I have the following basic interfaces in my project: interface X {}; interface Y {}; interface Data { x: X[]; y: Y[]; } And also this function: function fetchData<S extends keyof Data>(type: S): Data[S] { return data[type]; } ...

Step-by-step guide to initializing data within a service during bootstrap in Angular2 version RC4

In this scenario, I have two services injected and I need to ensure that some data, like a base URL, is passed to the first service so that all subsequent services can access it. Below is my root component: export class AppCmp { constructor (private h ...

Adding an arrow to a Material UI popover similar to a Tooltip

Can an Arrow be added to the Popover similar to the one in the ToolTip? https://i.stack.imgur.com/syWfg.png https://i.stack.imgur.com/4vBpC.png Is it possible to include an Arrow in the design of the Popover? ...

Error: Unable to locate specified column in Angular Material table

I don't understand why I am encountering this error in my code: ERROR Error: Could not find column with id "continent". I thought I had added the display column part correctly, so I'm unsure why this error is happening. <div class="exa ...

Unique component for customized form controls

Currently, I am delving into the world of Angular. One challenge I have been tackling is creating a custom form control that includes a mat-select. The goal is for the submitted form value to be the item selected in the dropdown. After sifting through num ...

Using Angular 6 to Format Dates

Can anyone provide instructions on how to achieve the following format in Angular? Expected: 20JAN2019 Currently, with the default Angular pipe, I am getting: 20/01/2019 when using {{slotEndDate | date:'dd/MM/yyyy'}} Do I need to write a ...

Develop a query builder in TypeORM where the source table (FROM) is a join table

I am currently working on translating this SQL query into TypeORM using the QueryBuilder: SELECT user_places.user_id, place.mpath FROM public.user_root_places_place user_places INNER JOIN public.place place ON place.id = user_places.place_id The ...

Embracing the power of Typescript with Node and Express?

While trying out the TypeScript Node Starter project from Microsoft, I found myself intrigued. Is it really possible to use TypeScript instead of Node on the server? There are a number of server-side tasks where TypeScript excels: - Building a web API ser ...

What is the best location to securely store API keys for my NodeJS application that is deployed using Elastic Beanstalk?

After developing an application using NodeJS that interacts with multiple third-party paid services via their API, I've taken precautions by refraining from committing the file containing these valuable API keys to my repository. However, as I prepare ...

What is the best practice for integrating MongoDB into a NodeJS application running on Elastic Beanstalk?

Currently, I am in the process of constructing a web application that requires a database to store user information. The company I am collaborating with intends to deploy the app on Elastic Beanstalk. As someone who is new to cloud technology, I feel compl ...

Conceal multiple parameters within routing for added security

I have setup my Angular component with a button that triggers an event. Inside this event, I currently have: this.router.navigate('page2') While I am aware that query parameters can be passed inside the URL, I am faced with the challenge of pas ...

The presence of a setupProxy file in a Create React App (CRA) project causes issues with the starting of react-scripts,

I have implemented the setupProxy file as outlined in the documentation: const proxy = require('http-proxy-middleware'); module.exports = function (app) { app.use( '/address', proxy({ target: 'http ...

Group records in MongoDB by either (id1, id2) or (id2, id1)

Creating a messaging system with MongoDB, I have designed the message schema as follows: Message Schema: { senderId: ObjectId, receiverId: ObjectId createdAt: Date } My goal is to showcase all message exchanges between a user and other users ...

A guide on effectively utilizing BehaviorSubject for removing items from an array

Currently, I am working on an Angular 8 application that consists of two components with a child-parent relationship. It came to my notice that even after removing an item from the child component, the item remains visible in the parent component's li ...