a. Enter your Salesforce username and password to log in to Salesforce.
b. Select Salesforce events for the types of data for Amazon AppFlow to process.
8. In the Choose Salesforce event drop-down, select the type of event to send to EventBridge.
9. For a destination, select Amazon EventBridge.
10. Select Create new partner event source.
11. (Optional) Specify a unique suffix for the partner event source.
12. Choose Generate partner event source.
13. Choose an Amazon S3 bucket to store event payload files that are larger than 256 KB.
14. In the Flow trigger section, ensure that Run flow on event is selected. This setting ensures that the flow is executed when a new Salesforce event occurs.
15. Choose Next.
16. For field mapping, select Map all fields directly. Alternatively, you can select the fields that are of interest from the Source field name list.
For more information about field mapping, see Map data fields.
17. Choose Next.
18. (Optional) Configure filters for data fields in Amazon AppFlow.
19. Choose Next.
20. Review the settings and then choose Create flow.
With the flow configured, Amazon AppFlow creates a new partner event source that you then need to associate with a partner event bus in your account.
Step 2: Configure EventBridge to receive Salesforce events
Ensure that the Amazon AppFlow flow that is triggered from Salesforce events with EventBridge as a destination is configured before following instructions in this section.
To configure EventBridge to receive Salesforce events
1. Open the Partner event sources page in the EventBridge console.
2. Select the Salesforce partner event source that you created in Step 1.
3. Choose Associate with event bus.
4. Validate the name of the partner event bus.
5. Choose Associate.
6. In the Amazon AppFlow console, open the flow you created and choose Activate flow.
7. Open the Rules page in the EventBridge console.
8. Choose Create rule.
9. Enter a unique name for the rule.
10. Choose Event pattern in the Define pattern section.
11. For Event matching pattern, select Pre-defined pattern by service.
12. For Service provider section, select All Events.
13. For Select event bus, choose Custom or partner event bus.
14. Select the event bus that you associated with the Amazon AppFlow partner event source.
Step 2: Configure EventBridge to receive Salesforce events
16. Choose Create.
The target service receives all Salesforce events configured for your account. To filter the events or send some events to different targets, you can use content-based filtering with event patterns (p. 26).
Note
For events larger than 256KB, Amazon AppFlow doesn't send the full event to EventBridge.Instead, Amazon AppFlow puts the event into an S3 bucket in your account, and then sends an event to EventBridge with a pointer to the Amazon S3 bucket. You can use the pointer to get the full event from the bucket.
Amazon EventBridge tutorials
EventBridge integrates with a number of AWS services and SaaS partners. These tutorials are designed to help you get familiar with the basics of EventBridge and how it can be part of your serverless architecture.
Tutorials:
• Amazon EventBridge get started tutorials (p. 104)
• Amazon EventBridge tutorials for integrating with other AWS services (p. 115)
• Amazon EventBridge tutorials for integrating with SaaS providers (p. 153)
Get started tutorials
Amazon EventBridge get started tutorials
The following tutorials help you explore the features of EventBridge and how to use them.
Tutorials:
• Archive and replay Amazon EventBridge events (p. 105)
• Create an Amazon EventBridge sample application (p. 108)
• Tutorial: Download code bindings for events using the EventBridge schema registry (p. 112)
• Tutorial: Use input transformer to customize what EventBridge passes to the event target (p. 113)
Archive and replay events
Archive and replay Amazon EventBridge events
You can use EventBridge to route events (p. 16) to specific AWS Lambda functions using rules (p. 34).
In this tutorial, you’ll create a function to use as the target for the EventBridge rule using the Lambda console. Then, you'll create an archive (p. 75) and a rule that'll archive test events using the EventBridge console. Once there are events in that archive, you'll replay (p. 77) them.
Steps:
• Step 1: Create a Lambda function (p. 105)
• Step 2: Create archive (p. 105)
• Step 3: Create rule (p. 106)
• Step 4: Send test events (p. 106)
• Step 5: Replay events (p. 106)
• Step 6: Clean up your resources (p. 107)
Step 1: Create a Lambda function
First, create a Lambda function to log the events.
To create a Lambda function:
1. Open the AWS Lambda console at https://console.aws.amazon.com/lambda/.
2. Choose Create function.
3. Choose Author from scratch.
4. Enter a name and description for the Lambda function. For example, name the function LogScheduledEvent.
5. Leave the rest of the options as the defaults and choose Create function.
6. On the Code tab of the function page, double-click index.js.
7. Replace the existing JavaScript code with the following code:
'use strict';
exports.handler = (event, context, callback) => { console.log('LogScheduledEvent');
console.log('Received event:', JSON.stringify(event, null, 2));
callback(null, 'Finished');
};
8. Choose Deploy.
Step 2: Create archive
Next, create the archive that will hold all the test events.
To create an archive
1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.
2. In the navigation pane, choose Archives.
Archive and replay events
6. Choose Create archive.
Step 3: Create rule
Create a rule to archive events that are sent to the event bus.
To create a rule
1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.
2. In the navigation pane, choose Rules.
3. Choose Create rule.
4. Enter a name and description for the rule. For example, name the rule ARTestRule.
5. For Define pattern, do the following:
a. Choose Event pattern.
b. Choose Custom pattern and paste the following code into the Event pattern field:
{ "detail-type": [ "customerCreated"
]}
c. Choose Save.
6. For Select event bus, choose AWS default event bus.
7. For Target, choose Lambda function.
8. For Function, select the Lambda function that you created in the Step 1: Create a Lambda function section. In this example, select LogScheduledEvent.
9. Choose Create.
Step 4: Send test events
Now that you've set up the archive and the rule, we'll send test events to make sure the archive is working correctly.
Note
It can take some time for events to get to the archive.To send test events (console)
1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.
2. In the navigation pane, choose Event buses.
3. In the Default event bus tile, choose Actions, Send events.
4. Enter an event source. For example, TestEvent.
5. For Detail type, enter customerCreated.
6. For Event detail, enter {}.
7. Choose Send.
Step 5: Replay events
Once the test events are in the archive you can replay them.
Archive and replay events
To replay archived events (console)
1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.
2. In the navigation pane, choose Replays.
3. Choose Start new replay.
4. Enter a name and description for the replay. For example, name the replay ReplayTest.
5. For Source, select the archive you created in the Step 2: Create archive section.
6. For Replay time frame, do the following.
a. For Start time, select the date you sent test events and a time before you sent them. For example, 2021/08/11 and 08:00:00.
b. For End time, select the current date and time. For example, 2021/08/11 and 09:15:00.
7. Choose Start Replay.
Step 6: Clean up your resources
You can now delete the resources that you created for this tutorial, unless you want to retain them. By deleting AWS resources that you are no longer using, you prevent unnecessary charges to your AWS account.
To delete the Lambda function(s)
1. Open the Functions page of the Lambda console.
2. Select the function(s) that you created.
3. Choose Actions, Delete.
4. Choose Delete.
To delete the EventBridge archives(s)
1. Open the Archives page of the EventBridge console.
2. Select the archive(s) you created.
3. Choose Delete.
4. Enter the archive name and choose Delete.
To delete the EventBridge rule(s)
1. Open the Rules page of the EventBridge console.
2. Select the rule(s) that you created.
3. Choose Delete.
4. Choose Delete.
Create a sample application
Create an Amazon EventBridge sample application
You can use EventBridge to route events (p. 16) to specific Lambda functions using rules (p. 34).
In this tutorial, you’ll use the AWS CLI, Node.js, and the code in the GitHub repo to create the following:
• An AWS Lambda function that produces events for bank ATM transactions.
• Three Lambda functions to use as targets (p. 50) of an EventBridge rule.
• and the rule that routes the created events to the correct downstream function based on an event pattern (p. 19).
This example uses AWS SAM templates to define the EventBridge rules. To learn more about using AWS SAM templates with EventBridge see ??? (p. 48).
In the repo, the atmProducer subdirectory contains handler.js, which represents the ATM service producing events. This code is a Lambda handler written in Node.js, and publishes events to EventBridge via the AWS SDK using this line of JavaScript code.
const result = await eventbridge.putEvents(params).promise()
This directory also contains events.js, listing several test transactions in an Entries array. A single event is defined in JavaScript as follows:
{
// Event envelope fields Source: 'custom.myATMapp', transactionId: '123456', cardPresent: true,
partnerBank: 'Example Bank', remainingFunds: 722.34 })}
The Detail section of the event specifies transaction attributes. These include the location of the ATM, the amount, the partner bank, and the result of the transaction.
The handler.js file in the atmConsumer subdirectory contains three functions:
exports.case1Handler = async (event) => { console.log('--- Approved transactions ---') console.log(JSON.stringify(event, null, 2)) }
exports.case2Handler = async (event) => {
console.log('--- NY location transactions ---') console.log(JSON.stringify(event, null, 2)) }
Create a sample application
exports.case3Handler = async (event) => { console.log('--- Unapproved transactions ---') console.log(JSON.stringify(event, null, 2)) }
Each function receives transaction events, which are logged via the console.log statements to Amazon CloudWatch Logs. The consumer functions operate independently of the producer and are unaware of the source of the events.
The routing logic is contained in the EventBridge rules that are deployed by the application’s AWS SAM template. The rules evaluate the incoming stream of events, and route matching events to the target Lambda functions.
The rules use event patterns that are JSON objects with the same structure as the events they match.
Here's the event pattern for the one of the rules.
{ "detail-type": ["transaction"], "source": ["custom.myATMapp"], "detail": {
"location": [{
"prefix": "NY-"
}]
} }
Steps:
• Prerequisites (p. 109)
• Step 1: Create application (p. 109)
• Step 2: Run application (p. 110)
• Step 3: Check the logs and verify the application works (p. 110)
• Step 4: Clean up your resources (p. 107)
Prerequisites
To complete this tutorial, you'll need the following resources:
• An AWS account. Create an AWS account if you don't already have one.
• AWS CLI installed. To install the AWS CLI, see the Installing, updating, and uninstalling the AWS CLI version 2.
• Node.js 12.x installed. To install Node.js, see Downloads.
Step 1: Create application
To set up the example application, you'll use the AWS CLI and Git to create the AWS resources you'll need.
To create the application
1. Sign in to AWS.2. Install Git and install the AWS Serverless Application Model CLI on your local machine.
Create a sample application
5. At the command line run the following command:
cd ./amazon-eventbridge-producer-consumer-example sam deploy --guided
6. In the terminal, do the following:
a. For Stack Name, enter a name for the stack. For example, name the stack Test.
b. For AWS Region, enter the Region. For example, us-west-2.
c. For Confirm changes before deploy, enter Y.
d. For Allow SAM CLI IAM role creation, enter Y e. For Save arguments to configuration file, enter Y f. For SAM configuration file, enter samconfig.toml.
g. For SAM configuration environment, enter default.
Step 2: Run application
Now that you've set up the resources, you'll use the console to test the functions.
To run the application
1. Open the Lambda console in the same Region where you deployed the AWS SAM application.
2. There are four Lambda functions with the prefix atm-demo. Select the atmProducerFn function, then choose Actions, Test.
3. Enter Test for the Name.
4. Choose Test.
Step 3: Check the logs and verify the application works
Now that you've run the application, you'll use the console to check the CloudWatch Logs.
To check the logs
1. Open the CloudWatch console in the same Region where you ran the AWS SAM application.
2. Choose Logs, and then choose Log groups.
3. Select the log group containing atmConsumerCase1. You see two streams representing the two transactions approved by the ATM. Choose a log stream to view the output.
4. Navigate back to the list of log groups, and then select the log group containing
atmConsumerCase2. You'll see two streams representing the two transactions matching the New York location filter.
5. Navigate back to the list of log groups, and select the log group containing atmConsumerCase3.
Open the stream to see the denied transactions.
Step 4: Clean up your resources
You can now delete the resources that you created for this tutorial, unless you want to retain them. By deleting AWS resources that you are no longer using, you prevent unnecessary charges to your AWS account.
To delete the EventBridge rule(s)
1. Open the Rules page of the EventBridge console.
Create a sample application
2. Select the rule(s) that you created.
3. Choose Delete.
4. Choose Delete.
To delete the Lambda function(s)
1. Open the Functions page of the Lambda console.
2. Select the function(s) that you created.
3. Choose Actions, Delete.
4. Choose Delete.
To delete the CloudWatch Logs log group(s)
1. Open the Cloudwatch console.2. Choose Logs, Log groups.
3. Select the log group(s) that were created in this tutorial.
4. Choose Actions, Delete log group(s).
5. Choose Delete.
Download code bindings for events using the EventBridge schema registry
Tutorial: Download code bindings for events using the EventBridge schema registry
You can generate code bindings (p. 86) for event schemas (p. 78) to speed development for Java, Python, and TypeScript. You can get code bindings for existing AWS services, schemas you create, and for
schemas you generate based on events (p. 16) on an event bus (p. 7). You can generate code bindings for a schema using one of the following:
• EventBridge console
• EventBridge schema registry API
• Your IDE with an AWS toolkit
In this tutorial you generate and download code bindings from an EventBridge schema for the events of an AWS service.
To generate code bindings from an EventBridge schema
1. Open the Amazon EventBridge console at https://console.aws.amazon.com/events/.
2. In the navigation pane, choose Schemas.
3. Select the AWS event schema registry tab.
4. Find the schema for the AWS service that you would like code bindings for, either by browsing through the schema registry, or by searching for a schema.
5. Select the schema name.
6. On the Schema details page, in the Version section, select Download code bindings.
7. On the Download code bindings page, select the language of the code bindings you want to download.
8. Select Download.
It may take a few seconds for your download to begin. The download file will be a .zip file of code bindings for the language you selected.
9. Unzip the downloaded file and add it to your project.
The downloaded package contains a README file that explains how to configure the package's dependencies in various frameworks.
Use these code bindings in your own code to help quickly build applications using this EventBridge event.
Use input transformer to customize what EventBridge passes to the event target
Tutorial: Use input transformer to customize what EventBridge passes to the event target
You can use the Input transformer (p. 71) in EventBridge to customize text from an event (p. 16) before you send it to the target of a rule (p. 34).
To do this, you define JSON paths from the event and assign their outputs to different variables. Then you can use those variables in the input template. The characters < and > can't be escaped. For more information, see Transforming Amazon EventBridge target input (p. 71)
Note
If you specify a variable to match a JSON path that doesn't exist in the event, that variable isn't created and doesn't appear in the output.In this tutorial, you create a rule that runs when any instance changes state. You extract the instance-id and state of an Amazon EC2 instance from the event. Then you use the input transformer to put that data into the message that goes to an Amazon SNS topic. The
For example, the rule in this tutorial matches the following Amazon EC2 instance state-change notification event.
{
"id":"7bf73129-1428-4cd3-a780-95db273d1602",
"detail-type":"EC2 Instance State-change Notification", "source":"aws.ec2",
"account":"123456789012", "time":"2015-11-11T21:29:54Z", "region":"us-east-1",
"resources":[
"arn:aws:ec2:us-east-1:123456789012:instance/ i-1234567890abcdef0"
],
"detail":{
"instance-id":" i-1234567890abcdef0", "state":"stopped"
} }
The input transformer maps the instance variable to the $.detail.instance-id JSON path from the event, and the state variable to the $.detail.state JSON path. Then EventBridge puts the variables into the input template "The EC2 instance <instance> has changed state to <state>." The result is the following Amazon SNS message.
The EC2 instance i-1234567890abcdef0 has changed state to stopped.
Steps:
• Step 1: Create a rule (p. 113)
• Step 2: Confirm success (p. 114)
• Step 3: Clean up your resources (p. 107)
Step 1: Create a rule
Create a rule to use the input transformer to customize the instance state information that goes to a target.
Use input transformer to customize what EventBridge passes to the event target 2. In the navigation pane, choose Rules.
3. Choose Create rule.
4. Type a name and description for the rule.
5. For Define pattern, do the following:
a. Choose Event pattern.
b. Choose Pre-defined pattern by service.
c. For Service provider, choose AWS.
d. For Service Name, choose EC2.
e. For Event type, choose EC2 Instance State-change Notification.
f. Choose Any state, Any instance.
6. For Select event bus, choose AWS default event bus. When an AWS service in your account emits an event, it goes to your account’s default event bus.
7. For Target, choose SNS topic.
8. For Topic, select the Amazon SNS topic that is to be notified when Amazon EC2 instances change state.
9. Choose Configure input, Input Transformer.
10. For Input Path, enter {"state" : "$.detail.state", "instance" : "$.detail.instance-id"}.
11. For Input Template, enter "The EC2 instance <instance> has changed state to <state>."
12. Choose Create.
Step 2: Confirm success
If you see the rule in the list of rules, you've successfully created the rule.
Step 3: Clean up your resources
You can now delete the resources that you created for this tutorial, unless you want to retain them. By deleting AWS resources that you are no longer using, you prevent unnecessary charges to your AWS account.
To delete the EventBridge rule(s)
1. Open the Rules page of the EventBridge console.
2. Select the rule(s) that you created.
3. Choose Delete.
4. Choose Delete.
AWS tutorials
Amazon EventBridge tutorials for integrating with other AWS services
Amazon EventBridge works with other AWS services to process events (p. 16) or invoke an AWS resource as the target (p. 50) of a rule (p. 34). The following tutorials show you how to integrate EventBridge with other AWS services.
Tutorials:
• Tutorial: Create an Amazon EventBridge rule for AWS CloudTrail API calls (p. 116)
• Tutorial: Log the state of an Auto Scaling group using EventBridge (p. 119)
• Tutorial: Log AWS API calls using EventBridge (p. 122)
• Tutorial: Log the state of an Amazon EC2 instance using EventBridge (p. 125)
• Tutorial: Log Amazon EC2 instance state changes (p. 128)
• Tutorial: Log Amazon S3 object-level operations using EventBridge (p. 130)
• Tutorial: Send events to an Amazon Kinesis stream using EventBridge (p. 133)
• Tutorial: Use EventBridge to relay events to AWS Systems Manager Run Command (p. 136)
• Tutorial: Run an Amazon ECS task when a file is uploaded to an Amazon S3 bucket (p. 138)
• Tutorial: Schedule automated Amazon EBS snapshots using EventBridge (p. 140)
• Tutorial: Schedule automated builds using AWS CodeBuild (p. 142)
• Tutorial: Send a notification when an Amazon S3 object is created (p. 144)
• Tutorial: Schedule AWS Lambda functions using EventBridge (p. 147)
• Tutorial: Set AWS Systems Manager Automation as an EventBridge target (p. 151)
Create rule based on CloudTrail API call
Tutorial: Create an Amazon EventBridge rule for AWS CloudTrail API calls
To create a rule (p. 34) that triggers on an action by an AWS service that doesn't generate events (p. 16), you can match API calls made by that service instead. AWS CloudTrail records API calls for some services.
For more information , see CloudTrail Supported Services and Integrations.
Rules in EventBridge only work in the Region where they're created. If you configure CloudTrail to track API calls in multiple Regions and you want a rule based on CloudTrail for each of those Regions, you must create a separate rule in each Region that you want to track.
All events that are delivered by CloudTrail have AWS API Call via CloudTrail as the value for detail-type. Events from API actions that start with the keywords List, Get, or Describe aren't
All events that are delivered by CloudTrail have AWS API Call via CloudTrail as the value for detail-type. Events from API actions that start with the keywords List, Get, or Describe aren't