79281426

Date: 2024-12-14 21:17:12
Score: 1
Natty:
Report link

As @gshpychka says, you should probably use the grantInvoke method instead. I wrote up an example here with an explanation, but basically all you need to do is as follows:

        // the target function will be invoked by the source function
        const targetFunction = new Function(this, "my-target-function", {
            runtime: Runtime.NODEJS_20_X,
            architecture: Architecture.ARM_64,
            handler: "target.handler",
            code: Code.fromAsset("./handlers/invocation"),
        });
        
        // the source function will be invoked by some event source
        const sourceFunction = new Function(this, "my-source-function", {
            runtime: Runtime.NODEJS_20_X,
            architecture: Architecture.ARM_64,
            handler: "source.handler",
            code: Code.fromAsset("./handlers/invocation"),
            environment: {
                // the source function will need the exact function name
                // as generated by CDK
                TARGET_LAMBDA_NAME: targetFunction.functionName,
            },
        });
        
        // we grant the invoke permission to the source function's principal,
        // so that the source function will be authorized to invoke the target
        // function
        targetFunction.grantInvoke(sourceFunction.grantPrincipal);
Reasons:
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @gshpychka
  • Low reputation (0.5):
Posted by: therightstuff