forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepfunctions-tasks): add sns publish with message attributes (a…
…ws#14817) This PR address aws#4702 I am primarily solving for the use case of using SNS publish with message attributes for sns filtering. If EventBridge integrations have a fast follow for wait for task token features, that would solve my use case. Because I'm solving for filtering and based on anecdotal experience String is the primary attribute type. I've included Binary because the pattern is the same. I have not implemented Number or String.Array because they are not Lambda supported and I believe less common. I chose to attempt to solve for consumer ergonomics with: ```ts const task = new SnsPublish(stack, 'Publish', { topic, message: sfn.TaskInput.fromText('Publish this message'), messageAttributes: { cake: { type: SnsMessageAttributeType.STRING, value: sfn.TaskInput.fromText('chocolate'), }, cakePic: { type: SnsMessageAttributeType.BINARY, value: sfn.TaskInput.fromDataAt('$.cake.pic'), }, }, }); ``` This results in a `value` member on the message attribute interface. While I think that maps best for the SNS json definition and does yield this ugly line in the private render methods: ``` attrs[a][`${attr.type}Value`] = attr.value.value; ``` Is there a better way? I did not implement SQS message attributes yet. Based on my limited knowledge the StepFunction integrations are similar(potentially identical if we again only support Binary and String). If the answer is one implementation, should I move the below code snippets into something generically named MessageAttribute within the stepfunctions package perhaps as part of base-task? ```ts /** * SNS Message Attribute type enum */ export enum SnsMessageAttributeType { /** * String type attributes. * * @see https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#SNSMessageAttributes.DataTypes */ STRING = 'String', /** * Binary type attributes. * * @see https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#SNSMessageAttributes.DataTypes */ BINARY = 'Binary', } /** * SNS Message Attribute */ export interface SnsMessageAttribute { /** * MessageAttributeType is the type of data being passed. * * * @see https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#SNSMessageAttributes.DataTypes */ readonly type: SnsMessageAttributeType; /** * The value of the data being passed */ readonly value: sfn.TaskInput; } ```
- Loading branch information
Showing
3 changed files
with
319 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters