constructor()

in src/triggers.ts [24:53]


  constructor(scope: Construct, id: string, props: AfterCreateProps) {
    super(scope, id);

    const provider = CustomResourceProvider.getOrCreateProvider(this, 'AWSCDK.TriggerCustomResourceProvider', {
      runtime: CustomResourceProviderRuntime.NODEJS_14_X,
      codeDirectory: join(__dirname, '..', 'lambda'),
      policyStatements: [
        {
          Effect: 'Allow',
          Action: ['lambda:InvokeFunction'],
          Resource: ['*'], // TODO?
        },
      ],
    });

    const resource = new CustomResource(this, 'Resource', {
      resourceType: 'Custom::Trigger',
      serviceToken: provider.serviceToken,
      properties: {
        // we use 'currentVersion' because a new version is created every time the
        // handler changes (either code or configuration). this will have the effect
        // that the trigger will be executed every time the handler is changed.
        HandlerArn: props.handler.currentVersion.functionArn,
      },
    });

    // add a dependency between our resource and the resources we want to invoke
    // after.
    resource.node.addDependency(...props.resources ?? []);
  }