https://pulumi.com logo
#golang
Title
# golang
g

green-morning-1318

03/10/2020, 9:19 PM
Are there any examples of how to create an API Gateway that invokes an AWS Lambda function using Go? I’ve tried a lot and it seems that I’m missing one final piece, but I can’t pinpoint what I’m missing. The calls I execute are: - lambda.NewFunction() to create a new function - apigateway.NewResource() to create thee resource in the API gateway - apigateway.NewMethod() to add a method to the above resource - apigateway.NewIntegration() to add the integration between the gateway and the function As the last step I add the Lambda permissions
Copy code
lambdaPermissions := &lambda.PermissionArgs{
    Action:    pulumi.String("lambda:InvokeFunction"),
    Function:  function.Name,
    Principal: pulumi.String("<http://apigateway.amazonaws.com|apigateway.amazonaws.com>"),
}

_, err = lambda.NewPermission(ctx, "AllCartsAPIPermission", lambdaPermissions)
if err != nil {
    return err
}
I don’t see the API Gateway showing up as a trigger in my Lambda function, but I’m not sure what I’ve missed. Any pointers are appreciated.
Aha! Got it!! I was missing the
SourceArn
field in the permission. The permissionArgs should have been something like:
Copy code
lambdaPermissions := &lambda.PermissionArgs{
			Action:    pulumi.String("lambda:InvokeFunction"),
			Function:  function.Name,
			Principal: pulumi.String("<http://apigateway.amazonaws.com|apigateway.amazonaws.com>"),
			SourceArn: pulumi.String("arn:aws:execute-api:us-west-2:ACCOUNTID:RESTAPI/*/GET/cart/all"),
		}
b

broad-dog-22463

03/10/2020, 10:05 PM
@green-morning-1318 if you have working code, I'd love you to open a PR that adds an example for others to learn from 🙂
Or you can share it with me, I can anonymize it and post it and attribute it to you
g

green-morning-1318

03/10/2020, 11:05 PM
Yeah, totally 🙌 which repo do you want me to create a PR for?
b

broad-dog-22463

03/10/2020, 11:08 PM
pulumi/examples
and tag me (@stack72) on it
thanks!!!
g

green-morning-1318

03/11/2020, 1:26 AM
Done 😇 https://github.com/pulumi/examples/pull/601 And I learned a few new things while looking at some of the other samples. Y’all do really good work with those 🙌
b

broad-dog-22463

03/11/2020, 1:33 AM
You rock! Thanks
g

green-morning-1318

03/11/2020, 1:49 AM
😳
3 Views