Buttonize logo

SNS Topic Message Form

SNS
SNS

Create a simple user interface for your team to publish messages to SNS topics. No need anymore to build cumbersome frontends, auth and APIs just to send a simple message to SNS topic.

SnsTopicMessageForm construct is a simple way how to enable anyone in the team to publish messages to SNS topics with pre-defined message shape.

Features

  • Easily send a message to SNS topic
  • Define arbitrary number of input fields
  • Resend the message again
  • Build a custom message shape
  • Display custom instructions to give a guidance to the users

Preview

SNS Topic Message Form App preview

Usage

lib/example-stack.ts
import * as cdk from 'aws-cdk-lib'
import { Topic } from 'aws-cdk-lib/aws-sns'
import { EmailSubscription } from 'aws-cdk-lib/aws-sns-subscriptions'
import { Buttonize, Input } from 'buttonize/cdk'
import { SnsTopicMessageForm } from 'buttonize/library'
import { Construct } from 'constructs'
export class ExampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
Buttonize.init(this, { apiKey: 'YOUR_API_KEY' })
const topic = new Topic(this, 'SnsTopic')
new SnsTopicMessageForm(this, 'TopicMessageForm', {
name: 'Product cache invalidation panel',
description:
'Trigger invalidation of a product in all the caches in the in the company systems',
topic,
submitButtonLabel: 'Invalidate',
fields: [
Input.text({
id: 'id',
label: 'Product ID'
}),
Input.select({
id: 'reason',
options: [
{ label: 'New manual update', value: 'manual_update' },
{ label: 'System bug', value: 'bug' }
]
})
],
messagePayload: {
operation: 'invalidate',
product: {
pid: '{{id}}'
},
metadata: {
reasonStatement: '{{reason.value}}'
}
}
})
topic.addSubscription(new EmailSubscription('your-email@example.com'))
}
}

SNS message payload sample.json
{
"operation": "invalidate",
"product": {
"pid": "p123456789"
},
"metadata": {
"reasonStatement": "manual_update"
}
}

Simplified key-value fields definition

Buttonize uses Input.text component for the input elements.

lib/example-stack.ts
new SnsTopicMessageForm(this, 'TopicMessageForm', {
topicArn: 'arn:aws:sns:<region>:<account-number>:<topic-name>',
fields: {
name: 'What is your name?'
}
/*
Same like:
fields: [
Input.text({
id: 'name',
label: 'What is your name?'
})
]
*/
})

SNS message payload sample.json
{
"name": "John Doe"
}
Setup
New repository
npx create-buttonize --template library/sns-topic-message-form --api-key=YOUR_API_KEY
Existing repository
import { Buttonize } from 'buttonize/cdk'
import { SnsTopicMessageForm } from 'buttonize/library'
Buttonize.init(this, { apiKey: 'YOUR_API_KEY' })
new SnsTopicMessageForm(this, 'MessageForm', {
topic: yourSnsTopic,
fields: {
name: 'What is your name?'
}
})
Deploy
npx cdk deploy
Delete
npx cdk destroy
Package
npm buttonize
Source
github SnsTopicMessageForm.ts
Additional resources

Buttonize X.com profile Buttonize GitHub profile

© 2024 Buttonize OÜ

With ❤️ made in 🇨🇿

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.