aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.59k stars 1.55k forks source link

EventBridge putRule/PutRuleCommand: ERROR ValidationException: 1 validation error detected: Value 'aws.partner/sellingpartnerapi.amazon.com/121212121212/amzn1.sp.solution.cb4023df-4e06-4fcf-a8a4-123e3a6544ee' at 'eventBusName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\.\-_A-Za-z0-9]+ #4572

Closed YAssineAbGit closed 8 months ago

YAssineAbGit commented 8 months ago

Describe the bug

I got the error below when calling either aws-sdks putRule function or @aws-sdk/client-eventBridge's PutRuleCommand instance, in AWS lambda Node20.x runtime environment. Despite adhering to what seems to be the correct format, I received a validation error related to the eventBusName parameter.

Error:

ERROR ValidationException: 1 validation error detected: 
Value 'aws.partner/sellingpartnerapi.amazon.com/121212121212/amzn1.sp.solution.cb4023df-4e06-4fcf-a8a4-123e3a6544ee' 
at 'eventBusName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\.\-_A-Za-z0-9]+

Expected Behavior

Creating an Event Rule without any errors as per Amazon Seller Partner API documentation As well as putRule function documentation

Current Behavior

The error is triggered when using aws-sdk putRule function Indicating a failure to satisfy the regular expression pattern for the eventBusName parameter.

2024-01-12T19:46:45.918Z    cb8e62db-3a75-4ab1-b7e0-b1b75af38105    ERROR ValidationException: 1 validation error detected: Value 'aws.partner/sellingpartnerapi.amazon.com/{aws_account}/amzn1.sp.solution.cb4023df-4e06-4fcf-a8a4-123e3a6544ee' at 'eventBusName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\.\-_A-Za-z0-9]+
    at constructor.tTf (/var/task/index.js:704:44721)
    at constructor.callListeners (/var/task/index.js:704:88345)
    at constructor.emit (/var/task/index.js:704:88052)
    at constructor.emitEvent (/var/task/index.js:705:29883)
    at constructor.e (/var/task/index.js:705:25430)
    at Vxr.runTo (/var/task/index.js:705:1227)
    at /var/task/index.js:705:1439
    at constructor.<anonymous> (/var/task/index.js:705:25647)
    at constructor.<anonymous> (/var/task/index.js:705:29938)
    at constructor.callListeners (/var/task/index.js:704:88451)
END RequestId: cb8e62db-3a75-4ab1-b7e0-b1b75af38105
REPORT RequestId: cb8e62db-3a75-4ab1-b7e0-b1b75af38105  Duration: 1231.87 ms    Billed Duration: 1232 ms    Memory Size: 512 MB Max Memory Used: 504 MB Init Duration: 2986.32 ms   

The official AWS documentation for the putRule function specifies the following pattern for EventBusName parameter (arn:aws[\w-]*:events:[a-z]{2}-[a-z]+-[\w-]+:[0-9]{12}:event-bus\/)?[/\.\-_A-Za-z0-9]+

However, I believe the correct pattern should be: (arn:aws[\w-]*:events:[a-z]{2}-[a-z]+-[\w-]+:[0-9]{12}:event-bus\/)?[\/\.\-_A-Za-z0-9]+

But the error I get is different, it mentions that it should satisfy this expression: [\.\-_A-Za-z0-9]+

Both the event bus arn and the event bus name were used and they both result in the same error.

Reproduction Steps

Follow the steps in the SP-API documentation to create a destination and an event bus in your AWS. Set up notifications (Amazon EventBridge workflow

Using aws-sdk

  const eventPattern = {
    source: [{ prefix: "aws.partner/sellingpartnerapi.amazon.com" }],
    "detail-type": [
         "LISTINGS_ITEM_STATUS_CHANGE",
         "LISTINGS_ITEM_ISSUES_CHANGE"
    ],
  };

 const busName = "aws.partner/sellingpartnerapi.amazon.com/{aws_account}/amzn1.sp.solution.cb4023df-4e06-4fcf-a8a4-123e3a6544ee"

 const eventBus: CreateEventBusResponse = await eventBridge
    .createEventBus({
      EventSourceName: busName,
      Name: busName,
    })
    .promise();

  const rule: PutRuleResponse = await eventBridge
    .putRule({
      Name: "ruleName",
      EventBusName: eventBus.EventBusArn, // Or we can use `busName`
      State: "ENABLED",
      EventPattern: JSON.stringify(eventPattern),
    })
    .promise();

Using @aws-sdk/client-eventbridge

...
const client = new EventBridgeClient({ region: ensureEnv("AWS_REGION") }); // replace "REGION" with your AWS region

  const command = new PutRuleCommand({
    Name: "ruleName",
    EventBusName:  "aws.partner/sellingpartnerapi.amazon.com/{aws_account}/amzn1.sp.solution.cb4023df-4e06-4fcf-a8a4-123e3a6544ee",
    State: "ENABLED",
    EventPattern: JSON.stringify(eventPattern),
  });

 await client.send(command);

Possible Solution

I am aware that there has been a similar issue with Serverless, and it has been resolved. You can find more information about the resolution at https://github.com/serverless/serverless/issues/6594.

Additional Information/Context

Note: that I get this error with both aws-sdk as well as @aws-sdk/client-eventbridge

SDK version used

"aws-sdk": "2.1534.0" && "@aws-sdk/client-eventbridge": "3.490.0"

Environment details (OS name and version, etc.)

AWS Lambda node 20.x runtime

YAssineAbGit commented 8 months ago

Sorry, this was my mistake this is unrelated to the putRule function. I am closing this issue