Skip to content

Commit 3de0c73

Browse files
committed
revamp eventbridge
1 parent 1bb5cf1 commit 3de0c73

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/content/docs/aws/services/events.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: "EventBridge"
3-
linkTitle: "EventBridge"
43
description: Get started with EventBridge on LocalStack
54
persistence: supported with limitations
65
tags: ["Free"]
@@ -14,12 +13,12 @@ EventBridge rules are tied to an Event Bus to manage event-driven workflows.
1413
You can use either identity-based or resource-based policies to control access to EventBridge resources, where the former can be attached to IAM users, groups, and roles, and the latter can be attached to specific AWS resources.
1514

1615
LocalStack allows you to use the EventBridge APIs in your local environment to create rules that route events to a target.
17-
The supported APIs are available on our [API coverage page]({{< ref "coverage_events" >}}), which provides information on the extent of EventBridge's integration with LocalStack.
18-
For information on EventBridge Pipes, please refer to the [EventBridge Pipes]({{< ref "user-guide/aws/pipes" >}}) section.
16+
The supported APIs are available on our [API coverage page](), which provides information on the extent of EventBridge's integration with LocalStack.
17+
For information on EventBridge Pipes, please refer to the [EventBridge Pipes]() section.
1918

20-
{{< callout >}}
19+
:::note
2120
The native EventBridge provider, introduced in [LocalStack 3.5.0](https://discuss.localstack.cloud/t/localstack-release-v3-5-0/947), is now the default in 4.0. The legacy provider can still be enabled using the `PROVIDER_OVERRIDE_EVENTS=v1` configuration, but it is deprecated and will be removed in the next major release. We strongly recommend migrating to the new provider.
22-
{{< /callout >}}
21+
:::
2322

2423
## Getting Started
2524

@@ -44,42 +43,42 @@ exports.handler = (event, context, callback) => {
4443

4544
Run the following command to create a new Lambda function using the [`CreateFunction`](https://docs.aws.amazon.com/cli/latest/reference/lambda/create-function.html) API:
4645

47-
{{< command >}}
48-
$ zip function.zip index.js
46+
```bash
47+
zip function.zip index.js
4948

50-
$ awslocal lambda create-function \
49+
awslocal lambda create-function \
5150
--function-name events-example \
5251
--runtime nodejs16.x \
5352
--zip-file fileb://function.zip \
5453
--handler index.handler \
5554
--role arn:aws:iam::000000000000:role/cool-stacklifter
56-
{{< /command >}}
55+
```
5756

5857
The output will consist of the `FunctionArn`, which you will need to add the Lambda function to the EventBridge target.
5958

6059
### Create an EventBridge Rule
6160

6261
Run the following command to create a new EventBridge rule using the [`PutRule`](https://docs.aws.amazon.com/cli/latest/reference/events/put-rule.html) API:
6362

64-
{{< command >}}
65-
$ awslocal events put-rule \
63+
```bash
64+
awslocal events put-rule \
6665
--name my-scheduled-rule \
6766
--schedule-expression 'rate(2 minutes)'
68-
{{< /command >}}
67+
```
6968

7069
In the above command, we have specified a schedule expression of `rate(2 minutes)`, which will run the rule every two minutes.
7170
It means that the Lambda function will be invoked every two minutes.
7271

7372
Next, grant the EventBridge service principal (`events.amazonaws.com`) permission to run the rule, using the [`AddPermission`](https://docs.aws.amazon.com/cli/latest/reference/events/add-permission.html) API:
7473

75-
{{< command >}}
76-
$ awslocal lambda add-permission \
74+
```bash
75+
awslocal lambda add-permission \
7776
--function-name events-example \
7877
--statement-id my-scheduled-event \
7978
--action 'lambda:InvokeFunction' \
8079
--principal events.amazonaws.com \
8180
--source-arn arn:aws:events:us-east-1:000000000000:rule/my-scheduled-rule
82-
{{< /command >}}
81+
```
8382

8483
### Add the Lambda Function as a Target
8584

@@ -96,11 +95,11 @@ Create a file named `targets.json` with the following content:
9695

9796
Finally, add the Lambda function as a target to the EventBridge rule using the [`PutTargets`](https://docs.aws.amazon.com/cli/latest/reference/events/put-targets.html) API:
9897

99-
{{< command >}}
100-
$ awslocal events put-targets \
98+
```bash
99+
awslocal events put-targets \
101100
--rule my-scheduled-rule \
102101
--targets file://targets.json
103-
{{< /command >}}
102+
```
104103

105104
### Verify the Lambda invocation
106105

@@ -109,27 +108,27 @@ However, wait at least 2 minutes after running the last command before checking
109108

110109
Run the following command to list the CloudWatch log groups:
111110

112-
{{< command >}}
113-
$ awslocal logs describe-log-groups
114-
{{< /command >}}
111+
```bash
112+
awslocal logs describe-log-groups
113+
```
115114

116115
The output will contain the log group name, which you can use to list the log streams:
117116

118-
{{< command >}}
119-
$ awslocal logs describe-log-streams \
117+
```bash
118+
awslocal logs describe-log-streams \
120119
--log-group-name /aws/lambda/events-example
121-
{{< /command >}}
120+
```
122121

123122
Alternatively, you can fetch LocalStack logs to verify the Lambda invocation:
124123

125-
{{< command >}}
126-
$ localstack logs
124+
```bash
125+
localstack logs
127126
...
128127
2023-07-17T09:37:52.028 INFO --- [ asgi_gw_0] localstack.request.aws : AWS lambda.Invoke => 202
129128
2023-07-17T09:37:52.106 INFO --- [ asgi_gw_0] localstack.request.http : POST /_localstack_lambda/97e08ac50c18930f131d9dd9744b8df4/invocations/ecb744d0-b3f2-400f-9e49-c85cf12b1e00/logs => 202
130129
2023-07-17T09:37:52.114 INFO --- [ asgi_gw_0] localstack.request.http : POST /_localstack_lambda/97e08ac50c18930f131d9dd9744b8df4/invocations/ecb744d0-b3f2-400f-9e49-c85cf12b1e00/response => 202
131130
...
132-
{{< /command >}}
131+
```
133132

134133
## Supported target types
135134

0 commit comments

Comments
 (0)