thundra-io / merloc

MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are still part of a flow in the AWS cloud remote.
Apache License 2.0
193 stars 8 forks source link

Feature Request: Publish the Broker as a CDK Construct Lib #2

Open misterjoshua opened 2 years ago

misterjoshua commented 2 years ago

Please publish the MerLoc Broker as an AWS CDK v2 Construct Lib.

Use Case

We'd like to add the MerLoc Broker to our existing CDK App so that it comes for free in our developers' environments. This would simplify MerLoc's setup for our entire team.

Example

/** Use the MerLocBroker's addLambdaFunction */
export class MyStack extends Stack {
  constructor(scope: Construct, id: string, props: StackProps = {}) {
    super(scope, id, props);

    // I add a MerLoc broker to my existing app.
    const merLocBroker = new MerLocBroker(this, 'MerLocBroker');

    // Lets say I have a specific function I want to configure to use the broker.
    const handler = new aws_lambda.Function(this, 'MyFunction', {...});
    // I add the lambda function to the MerLocBroker, and this auto-configures
    // the function with the correct layer and environment variables to use the broker.
    merLocBroker.addLambdaFunction(handler);
  }
}

/** An aspect-based approach */
export class MyStack2 extends Stack {
  constructor(scope: Construct, id: string, props: StackProps = {}) {
    super(scope, id, props);

    // Lets say this is my app - I have data and control planes.
    const myAppData = new MyAppData(this, 'MyAppData');
    new MyAppControl(this, 'MyAppControl', {
      myAppData,
    });

    // I add a MerLoc broker to my existing app.
    const merLocBroker = new MerLocBroker(this, 'MerLocBroker');
    // Then add an aspect that auto-configures all my lambdas with the correct
    // layer and environment variables to use the broker.
    Aspects.of(this).add(
      new MerLocConfigAspect(merLocBroker),
    );
  }
}