hey guys — is it possible to define and subscribe ...
# help
j
hey guys — is it possible to define and subscribe a sqs queue to an sns topic in serverless-stack?
f
You can do something like:
Copy code
const queue = sst.Queue(...);
const topic = sst.Topic(...);

topic.snsTopic.addSubscription(new subscriptions.SqsSubscription(queue.sqsQueue));
j
cool, I’ll try that out. Thank you @Frank!
also — do you support creating service proxy integrations? e.g. Api Gateway publishing to SNS directly
f
Yeah..i’m looking at the docs too
are you using the
sst.Api
construct?
j
right now I’m deciding how to build this 😄 I’m happy to put a lambda in the middle to receive the data we need from an HTTP endpoint and publish to SNS. But I’d much rather avoid creating a lambda only to do this and just forward it from API Gateway to SNS directly
f
Maybe see if EventBridge works for you?
j
hmm, I’m sure I’ve done this by hand before directly in Api Gateway, maybe not directly using a service integration? I guess I was just using a mapping template and then forwarding a POST directly to SNS
f
Oh, I think you were probably using REST Api.
j
oh sorry, that could indeed be it. I guess I was not educated enough in the different api gateway api types
so is it the difference that the HTTP api cannot do an integration request, whereas the REST Api can?
f
HTTP Api integrates with a limited number of AWS services. Based on the link above, it seems HTTP Api can integrate with SQS, Step Functions and a couple of other AWS services.
SNS isn’t in the list.
j
right — I’m ok with using a REST Api, I’m just not so sure whether the ApiGatewayV1Api construct allows for that, or whether I should fall back to using bare CDK if I wanted to accomplish that
of course I’m taking for granted I could just use a HTTP Api and route to SNS through lambda as well, just trying to understand what’s possible
f
yeah.. I’m biased towards using HTTP Api. But if you were to go with REST Api, you’d need to use bare CDK for the time being.
ApiGatewayV1Api
doesn’t have a high level abstraction for that yet.
@José Ribeiro in v0.22.0, I added the ability for Queue to subscribe to a Topic. It should simplify ur code a bit:
Copy code
const queue = sst.Queue(...);

const topic = sst.Topic(this, "MyTopic", {
  subscribers: [queue],
});