Are there any examples of how to create an API Gat...
# golang
g
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
@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
Yeah, totally 🙌 which repo do you want me to create a PR for?
b
pulumi/examples
and tag me (@stack72) on it
thanks!!!
g
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
You rock! Thanks
g
😳