Last active
November 17, 2021 09:11
-
-
Save sam-goodwin/d7f1bd207897903de12f3477069663fe to your computer and use it in GitHub Desktop.
Lambda => SNS in punchcard
This file contains hidden or 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
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() | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sam-goodwin 👍