Skip to content

Instantly share code, notes, and snippets.

@sam-goodwin
Last active November 17, 2021 09:11
Show Gist options
  • Save sam-goodwin/d7f1bd207897903de12f3477069663fe to your computer and use it in GitHub Desktop.
Save sam-goodwin/d7f1bd207897903de12f3477069663fe to your computer and use it in GitHub Desktop.
Lambda => SNS in punchcard
import cdk = require('@aws-cdk/core');
import { Function, Topic, string, integer, timestamp } from 'punchcard';
const app = new cdk.App();
export default app;
const stack = new cdk.Stack(app, 'my-stack');
// create a type-safe SNS Topic
const topic = new Topic(stack, 'Topic', {
type: struct({
key: string(),
count: integer(),
timestamp
})
});
new Function(stack, 'MyFunction', {
// depend on the topic
depends: topic,
handle: async (event, topic) => {
// our handle implementation is passed a type-safe pre-initialized 'topic' instance which can be interacted with
await topic.publish({
key: 'some key',
count: 1,
timestamp: new Date()
});
}
});
@DanielBoa
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment