Hi Everyone, I was wondering if anyone has come ac...
# help
Hi Everyone, I was wondering if anyone has come across trying to lambda function invocations within an API gateway triggered lambda function? Would it be best to declare the function as a standalone in the "myStack.js" and then invoke it using the aws-sdk?
I've been doing exactly this and it works just fine
In Node, it looks something like this
import {LambdaClient, InvokeCommand} from "@aws-sdk/client-lambda"; const lambda = new LambdaClient({region: process.env.region}); await lambda.send( new InvokeCommand({ FunctionName: "LAMBDA_FUNCTION_NAME_HERE" InvocationType: "Event", Payload: Buffer.from(JSON.stringify({body: message})) })
That's using aws-sdk v3, but the same strategy applies to aws sdk v2
Hey Seth, Awesome thank you for the quick reply!
Seems to work fine I just have a permission issue on the Invocation
"is not authorized to perform: lambda:InvokeFunction on resource"
We're you able to figure that out?
ERROR AccessDeniedException: User: {dev-my-sst-app-my-stack-ApiLambda} is not authorized to perform: lambda:InvokeFunction on resource: {arnawslambdaus eastfunction}
I can't seem to figure out the right permissions profile to get this to work. Am I supposed to give the API stack full permissions or the function that's being invoked?
you could probably do it either way. In my case, I added the permission directly to the function because i wasn't exposing it via an API
Which looks like const myLambda = new sst.Function(...) const otherLambda = new sst.Function(...) myLambda.attachPermissions([new iam.PolicyStatement({ actions: ["lambda:InvokeFunction"], effect: iam.Effect.ALLOW, resources: [otherLambda.functionArn] })]);
but you could add it the the API route as well
api.attachPermissionsToRoute("GET /YOUR_ROUTE", [new iam.PolicyStatement({         actions: ["lambda:InvokeFunction"],         effect: iam.Effect.ALLOW,         resources: [otherLambda.functionArn]       })]);
there's probably a better shorthand to add the Invoke permission, but that's what I know off the top of my head 🙂
Unreal! Thank you
I like that second method very cool!