I'm implementing a AWS v3 event bridge from inside a Typescript application we have, using this library https://www.npmjs.com/package/@aws-sdk/client-eventbridge however when I run this code:
import { EventBridgeClient, ActivateEventSourceCommand } from "@aws-sdk/client-eventbridge";
const client = new EventBridgeClient({ region: process.env.AWS_REGION });
// this is the BODY section of what is sent
const dataToSend = {
email_address: user_email,
status: action,
merge_fields: {
FNAME: user_givenName,
LNAME: user_familyName,
},
interests: interestId,
};
const entry = {
Entries: [
{
EventBusName: "Subscriptions",
Source: "custom.subscriptions",
DetailType: "subscription",
Detail: JSON.stringify(dataToSend),
},
],
};
const params = {
Name: "TestBus",
Description: "data bus",
Entry: JSON.stringify(entry),
};
const command = new ActivateEventSourceCommand(params);
try {
const data = await client.send(command);
// process data.
console.log("data>>", data);
} catch (error) {
// error handling.
console.log("err>>", error);
}
I get the error:
err>> ValidationException: 1 validation error detected: Value 'TestBus' at 'name' failed to satisfy constraint: Member must satisfy regular expression pattern: aws.partner(/[.-_A-Za-z0-9]+){2,}
Running the regex through this site: https://www.regextester.com/ it's shown as the forward slash is invalid.
Looking through the supplied code, I can see the 'Name' parameter should be a string, and other examples I've viewed have a similar name to the one I am using. What is wrong with my code?
Looks like I had two issues in there:
EventBusName: "Subscriptions",
should be:
EventBusName: "default",
(or create the new EventBus, with the name supplied) and ActivateEventSourceCommand
should be PutEventsCommand
removing the params
const and with the command as:
const command = new PutEventsCommand(entry);
[edit] Also opened this as a Github bug and received this reply: https://github.com/aws/aws-sdk-js-v3/issues/2804 - hope that helps someone in the future!!