Hi SST fam. This isn’t specific to SST in general,...
# help
v
Hi SST fam. This isn’t specific to SST in general, but figured people might be able to help me with this. How can I set SNS delivery policy (maxReceivesPerSecond) via CDK?
f
Hey @Vignesh Rajagopalan, I just read up on the CDK doc, it seems CDK doesn’t support
deliveryPolicy
in the
sns.Subscription
construct yet.
I think the best approach for now is if the
sst.Topic
construct exposed the `sns.Subscription`s it created internally, and you can the CloudFormation resource from it and set the
deliveryPolicy
at the CloudFormation level. It would look something like:
Copy code
const topic = sst.Topic(...);
topic.snsSubscriptions[0].node.defaultChild.deliveryPolicy = {
  throttlePolicy: { "maxReceivesPerSecond": 10 }
};
Just to add a bit of context,
.node.defaultChild
gives you the low level CloudFormation resource
Would that work for you?
v
Hey Frank! Thanks for getting back on this 🙂 So this is basically working at a lower level than where we’d usually work at. L1? I will try this out. If this is possible, then this should work out for me.
f
I need to push out a change to expose
topic.snsSubscriptions
I will have that included in the next release.
v
Thanks a lot 🙂 That’d be of a great help
f
@Vignesh Rajagopalan aight it’s out in v0.15.0.
I put together some code sample. This sets the
maxReceivesPerSecond
to the first subscriber for the topic.
Copy code
const topic = new sst.Topic(stack, "Topic", {
    subscribers: ["test/lambda.handler"],
  });
  const subscription = topic.snsSubscriptions[0];
  const cfnSub = subscription.node.defaultChild as sns.CfnSubscription;
  cfnSub.deliveryPolicy = {
    throttlePolicy: { "maxReceivesPerSecond": 10 }
  };
v
This is great!! Pulling the new release right away ❤️