File tree Expand file tree Collapse file tree 10 files changed +31
-25
lines changed Expand file tree Collapse file tree 10 files changed +31
-25
lines changed Original file line number Diff line number Diff line change @@ -20,30 +20,36 @@ bring eventbridge;
20
20
21
21
let bus = new eventbridge.Bus (name: " my-bus" );
22
22
23
- bus .subscribeFunction (" github.pull-request.created" , inflight (event ) => {
23
+ bus .onEvent (" github.pull-request.created" , inflight (event ) => {
24
24
log (" subscribed event received {Json.stringify(event)}" );
25
25
}, {
26
26
" detail-type" : [{" prefix" : " pull-request." }],
27
27
" source" : [" github.com" ],
28
28
});
29
29
30
30
new cloud.Function (inflight () => {
31
- bus .putEvents ([ {
31
+ bus .putEvents ({
32
32
detailType: " pull-request.created" ,
33
33
resources: [" test" ],
34
34
source: " github.com" ,
35
35
version: " 0" ,
36
36
detail: {
37
37
" test" : " test" ,
38
38
},
39
- }] );
39
+ });
40
40
});
41
41
```
42
42
43
43
## Parameters
44
44
45
45
* eventBridgeName - ` str ` - Optional. Name of an existing EventBridge to reference.
46
46
47
+ #### Usage
48
+
49
+ ``` sh
50
+ wing compile -t @winglang/platform-awscdk -v eventBridgeName=" my-bus" main.w
51
+ ```
52
+
47
53
## License
48
54
49
55
This library is licensed under the [ MIT License] ( ./LICENSE ) .
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class InboundGithubEvents {
13
13
this.bucket = new cloud.Bucket();
14
14
let counter = new cloud.Counter();
15
15
16
- eventBridge.subscribeFunction ("github.pull-request.created", inflight (event) => {
16
+ eventBridge.onEvent ("github.pull-request.created", inflight (event) => {
17
17
log("subscribed event received {Json.stringify(event)}");
18
18
this.bucket.put("test-{counter.inc()}", Json.stringify(event));
19
19
}, {
@@ -46,15 +46,15 @@ let env = new Environments();
46
46
47
47
test "publish to eventbridge" {
48
48
log("publishing to eventbridge");
49
- eventBridge.putEvents([ {
49
+ eventBridge.putEvents({
50
50
detailType: "pull-request.created",
51
51
resources: ["test"],
52
52
source: "github.com",
53
53
version: "0",
54
54
detail: {
55
55
"test": "test",
56
56
},
57
- }] );
57
+ });
58
58
59
59
log("published");
60
60
@@ -73,15 +73,15 @@ test "publish to eventbridge" {
73
73
74
74
expect.equal(0, env.bucket.list().length);
75
75
76
- eventBridge.putEvents([ {
76
+ eventBridge.putEvents({
77
77
detailType: "myTest.check",
78
78
resources: ["test"],
79
79
source: "myTest",
80
80
version: "0",
81
81
detail: {
82
82
"fake": "env",
83
83
},
84
- }] );
84
+ });
85
85
86
86
log("published 2nd event");
87
87
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ bring "./platform/awscdk" as awscdk;
11
11
pub class Bus impl types.IBus {
12
12
inner: types.IBus;
13
13
14
- new(props: types.BusProps) {
14
+ new(props: types.BusProps? ) {
15
15
let target = util.env("WING_TARGET");
16
16
if target == "sim" {
17
17
this.inner = new sim.Bus(props) as "sim";
@@ -24,12 +24,12 @@ pub class Bus impl types.IBus {
24
24
}
25
25
}
26
26
27
- pub inflight putEvents(events: Array<types.PublishEvent>): void {
27
+ pub inflight putEvents(... events: Array<types.PublishEvent>): void {
28
28
this.inner.putEvents(events);
29
29
}
30
30
31
- pub subscribeFunction (name: str, handler: inflight (types.Event): void, pattern: Json): void {
32
- this.inner.subscribeFunction (name, handler, pattern);
31
+ pub onEvent (name: str, handler: inflight (types.Event): void, pattern: Json): void {
32
+ this.inner.onEvent (name, handler, pattern);
33
33
}
34
34
pub subscribeQueue(name: str, queue: cloud.Queue, pattern: Json): void {
35
35
this.inner.subscribeQueue(name, queue, pattern);
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @winglibs/eventbridge" ,
3
3
"description" : " Amazon EventBridge library for Wing" ,
4
- "version" : " 0.0.4 " ,
4
+ "version" : " 0.1.0 " ,
5
5
"repository" : {
6
6
"type" : " git" ,
7
7
"url" : " https://github.com/winglang/winglibs.git" ,
Original file line number Diff line number Diff line change @@ -9,17 +9,17 @@ pub class Bus impl types.IBus {
9
9
10
10
eventBridge: cdk.aws_events.IEventBus;
11
11
12
- new(props: types.BusProps) {
12
+ new(props: types.BusProps? ) {
13
13
let app = nodeof(this).app;
14
14
// TODO: use typed properties when its available
15
15
if let eventBridgeName = app.parameters.value("eventBridgeName") {
16
16
this.eventBridge = cdk.aws_events.EventBus.fromEventBusName(this, "EventBridge", eventBridgeName);
17
17
} else {
18
- this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props.name) as "EventBridge";
18
+ this.eventBridge = new cdk.aws_events.EventBus(eventBusName: props? .name ?? "eventbridge-{this.node.addr.substring(0, 8)}" ) as "EventBridge";
19
19
}
20
20
}
21
21
22
- pub subscribeFunction (name: str, handler: inflight (types.Event): void, pattern: Json): void {
22
+ pub onEvent (name: str, handler: inflight (types.Event): void, pattern: Json): void {
23
23
// event will be json of type `types.Event`
24
24
let funk = new cloud.Function(inflight (event) => {
25
25
// since wing structs don't supoort custom serialization we need to do it manually
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ pub class EventBridgeBus {
7
7
topic: cloud.Topic;
8
8
var handlerCount: num;
9
9
10
- new(props: types.BusProps) {
10
+ new(props: types.BusProps? ) {
11
11
this.topic = new cloud.Topic() as "EventBridge";
12
12
13
13
this.handlerCount = 0;
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ bring "./bus.w" as bus;
5
5
pub class Bus impl types.IBus {
6
6
bus: bus.EventBridgeBus;
7
7
8
- new(props: types.BusProps) {
8
+ new(props: types.BusProps? ) {
9
9
this.bus = new bus.EventBridgeBus(props);
10
10
}
11
11
12
- pub subscribeFunction (name: str, handler: inflight (types.Event): void, pattern: Json): void {
12
+ pub onEvent (name: str, handler: inflight (types.Event): void, pattern: Json): void {
13
13
class FnRule {
14
14
new(bus: bus.EventBridgeBus) {
15
15
let onMessageHandler = bus.subscribe(inflight (event) => {
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ pub class Bus impl types.IBus {
9
9
busName: str;
10
10
busArn: str;
11
11
12
- new(props: types.BusProps) {
12
+ new(props: types.BusProps? ) {
13
13
let app = nodeof(this).app;
14
14
// TODO: use typed properties when its available
15
15
if let eventBridgeName = app.parameters.value("eventBridgeName") {
@@ -19,13 +19,13 @@ pub class Bus impl types.IBus {
19
19
this.busName = bus.name;
20
20
this.busArn = bus.arn;
21
21
} else {
22
- let bus = new tfAws.cloudwatchEventBus.CloudwatchEventBus(name: props.name) as "EventBridge";
22
+ let bus = new tfAws.cloudwatchEventBus.CloudwatchEventBus(name: props? .name ?? "eventbridge-{this.node.addr.substring(0, 8)}" ) as "EventBridge";
23
23
this.busName = bus.name;
24
24
this.busArn = bus.arn;
25
25
}
26
26
}
27
27
28
- pub subscribeFunction (name: str, handler: inflight (types.Event): void, pattern: Json): void {
28
+ pub onEvent (name: str, handler: inflight (types.Event): void, pattern: Json): void {
29
29
let rule = new tfAws.cloudwatchEventRule.CloudwatchEventRule(
30
30
name: name,
31
31
eventBusName: this.busName,
Original file line number Diff line number Diff line change @@ -27,6 +27,6 @@ pub struct PublishEvent {
27
27
28
28
pub interface IBus extends std.IResource {
29
29
inflight putEvents(events: Array<PublishEvent>): void;
30
- subscribeFunction (name: str, handler: inflight (Event): void, pattern: Json): void;
30
+ onEvent (name: str, handler: inflight (Event): void, pattern: Json): void;
31
31
subscribeQueue(name: str, queue: cloud.Queue, pattern: Json): void;
32
32
}
You can’t perform that action at this time.
0 commit comments