-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stepfunctions-tasks): add sns publish with message attributes #14817
feat(stepfunctions-tasks): add sns publish with message attributes #14817
Conversation
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; } ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding in line comments similar to the summary for comment tracking.
@shivlaks I think you indicated some interest in a PR here, if you have something ready feel free to push and take the lead. |
Ok I've realized I did not understand the value/flexibility of If we can agree that we will only support const pubTask = new SnsPublish(stack, 'Publish', {
topic,
message: sfn.TaskInput.fromText('Publish this message'),
messageAttributes: {
cake: sfn.TaskInput.fromText('chocolate'),
attribute2: sfn.TaskInput.fromDataAt('$.attribute2'),
},
}); I prefer the above because it's the only use case I've seen in the wild and most simple to declare. @shivlaks are you able to help here at all? |
packages/@aws-cdk/aws-stepfunctions-tasks/test/sns/publish.test.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Shiv Lakshminarayan <shivlaks@amazon.com>
I think I still have a question here. If we agree String support is the only type we can simplify a lot of code.
I think part of my confusion is where do I need to enforce they use sfn.TaskInput versus just using literal strings and JsonPath? |
I think overall, I'd like to support more than just strings. The current split of only allowing task input in the attribute value is fine for me. This is a design decision that we should align on, but I think it's a realistic tradeoff as allowing too much flexibility removes all the nice type checking, serialization, etc. that we can do |
I’ve got some free time next week. I like the feedback I’ll make some
changes.
…On Fri, Jul 2, 2021 at 10:00 PM Ben Chaimberg ***@***.***> wrote:
I think overall, I'd like to support more than just strings. The current
split of only allowing task input in the attribute value is fine for me.
This is a design decision that we should align on, but I think it's a
realistic tradeoff as allowing too much flexibility removes all the nice
type checking, serialization, etc. that we can do
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#14817 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFCFWBZTQYA5LZNHEC7F73TV2KPXANCNFSM45IRPQDQ>
.
|
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Pull request has been modified.
This comment #14817 (comment) represents what I believe to be blocking finishing this work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the auto-detect, feels very powerful for our customers! Just a few major comments, rest are naming/implementation details
packages/@aws-cdk/aws-stepfunctions-tasks/test/sns/publish.test.ts
Outdated
Show resolved
Hide resolved
I agree with comments @BenChaimberg and will get a refactor up this week. |
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Pull request has been modified.
Pull request has been modified.
@BenChaimberg - I think I've now addressed all of your comments. Can you please give me another review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! Just a couple of minor things and I think we'll be good to go!
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Pull request has been modified.
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Co-authored-by: Ben Chaimberg <youppi3@gmail.com>
Pull request has been modified.
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…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; } ```
…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; } ```
This PR address #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:
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:
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?