Send Mongo Change Event to AWS Global Endpoint

62 Views Asked by At

I am attempting to use Mongo Atlas App Services to send document change events to a AWS Global Endpoint. I understand Mongo Atlas has a built in partner integration with AWS and you can wire up the trigger to EventBridge but I am hoping to take advantage of the Global Endpoint Failover as well as have control over the event bus the event is thrown on. Below is the function I am attempting to use to send the events via the AWS SDK.

exports = async function (arg) {
    const {
    EventBridgeClient,
    PutEventsCommand,
  } = require("@aws-sdk/client-eventbridge");
  require("@aws-sdk/signature-v4-crt");
  
  // Access key and secret tied to IAM User
    const awsAccessKeyId = context.values.get('AWS_ACCESS_KEY_ID');
    const awsSecretAccessKey = context.values.get('AWS_SECRET_ACCESS_KEY');
  
    const credentials = {
      accessKeyId: awsAccessKeyId,
      secretAccessKey: awsSecretAccessKey,
    };
  
    const client = new EventBridgeClient({ region: "us-east-2", credentials });
    const command = new PutEventsCommand({
      Entries: [{
      Detail: JSON.stringify(arg),
      DetailType: `MongoDB Trigger`,
      EventBusName: 'ride-the-bus',
      Source: "Atlas Mongo",
      Resource: []
    }],
    // Scrambled Global Endpoint.
      EndpointId: "y3dksii7is.ypm"
    });
  
    try {
      const res = await client.send(command);
      console.log(res);
    } catch (error) {
      console.log(error);
    }
  };

In a local node service running the same Node v10.18 I don't have issues.

  • I am using version 3.45.0 for both @aws-sdk/client-eventbridge and @aws-sdk/signature-v4-crt as that supposedly supports >= Node v10.16.

Below is the error I am getting for any version of the aws-sdk modules.

> error: 
failed to execute source for 'node_modules/@aws-sdk/signature-v4-crt/dist-cjs/index.js': FunctionError: failed to execute source for 'node_modules/@aws-sdk/signature-v4-crt/dist-cjs/CrtSignerV4.js': FunctionError: failed to execute source for 'node_modules/aws-crt/dist/index.js': FunctionError: failed to execute source for 'node_modules/aws-crt/dist/native/auth.js': FunctionError: failed to execute source for 'node_modules/aws-crt/dist/native/binding.js': Error: The current runtime is not reporting an NAPI version. Please upgrade to node >=10.16.0, or use the provided browser implementation.
    at node_modules/aws-crt/dist/native/binding.js:95:9(112)
0

There are 0 best solutions below