pulumi / examples

Infrastructure, containers, and serverless apps to AWS, Azure, GCP, and Kubernetes... all deployed with Pulumi
https://www.pulumi.com
Apache License 2.0
2.36k stars 877 forks source link

aws.sns.TopicSubscription with protocol 'sqs' creates a faulty subscription #1558

Open zestsystem opened 8 months ago

zestsystem commented 8 months ago

What happened?

When using pulumi to create subscription between sns topic and sqs queue, while the subscription is created and viewable on AWS dashboard, does not work (messages are not consumed). However, after manually subscribing to the topic from the console, sqs starts pulling from the topic.

Example

IaC

import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
const orderEventsTopic = new aws.sns.Topic('orderEvents', {
    contentBasedDeduplication: true,
    fifoTopic: true,
});
export const snsOrderEventsArn = orderEventsTopic.arn;

const fulfillOrderQueue = new aws.sqs.Queue('fulfillOrder', {
    contentBasedDeduplication: true,
    fifoQueue: true,
});
export const sqsFulfillOrderUrl = fulfillOrderQueue.url;
const fulfillOrderSubscription = new aws.sns.TopicSubscription('fulfillOrderSubscription', {
    protocol: 'sqs',
    endpoint: fulfillOrderQueue.arn,
    topic: orderEventsTopic.arn,
    rawMessageDelivery: true,
    filterPolicyScope: 'MessageBody',
    filterPolicy: JSON.stringify({
        event: ['order-fulfilled'],
    }),
});

Publisher


import { SNSClient, PublishCommand, type SNSClientConfig } from '@aws-sdk/client-sns';

export class OrderEventsPublisher {
    private readonly sns: SNSClient;
    private readonly topicArn: string;

    constructor(config: SNSClientConfig, topicArn: string) {
        this.sns = new SNSClient(config);
        this.topicArn = topicArn;
    }

    async orderFulfilled(message: { ticketOrderId: number }) {
        const command = new PublishCommand({
            TopicArn: this.topicArn,
            MessageGroupId: message.ticketOrderId.toString(),
            Message: JSON.stringify(message),
            MessageAttributes: {
                event: {
                    DataType: 'String',
                    StringValue: 'order-fulfilled',
                },
            },
        });

        console.log('Publish command: ', command);

        const response = await this.sns.send(command);

        console.log('Response: ', response);

        return response;
    }
}

Output of pulumi about

CLI
Version 3.93.0 Go Version go1.21.5 Go Compiler gc

Host
OS darwin Version 13.5 Arch arm64

Backend
Name pulumi.com URL https://app.pulumi.com/zestsystem User zestsystem Organizations zestsystem, utc Token type personal

Pulumi locates its logs in /var/folders/pf/34pz6n095dz0b0q2ph6xst_c0000gn/T/ by default warning: Failed to read project: no Pulumi.yaml project file found (searching upwards from /Users/mikeyim/projects/work/utc). If you have not created a project yet, use pulumi new to do so: no project file found warning: Failed to get information about the current stack: no Pulumi.yaml project file found (searching upwards from /Users/mikeyim/projects/work/utc). If you have not created a project yet, use pulumi new to do so: no project file found

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).