I am using Strong loop in AWS Lambda and i want to trigger it somehow. The only available option right now is APi Gateway. Is there a way to create one resource and pass all its requests to single lambda function?
I want to achieve something like this
/api/* --> Lambda Function
Does AWS support this?
This is supported by API gateway proxy resource. You can create a special path parameter {proxy+} which represents any child resource of a parent API. The ANY method can be used to catch all http methods on that resource.
In your case, you need to create an api resource /api and under that, create a new proxy resource {proxy+}. If you are creating it through the AWS console, you just have to check the check box for the option Configure as proxy resource while creating the resource. When you get to the integration setup, select Lambda Function Proxy as your integration type, choose the region and select the lambda function you want to invoke.
This is described in detail in the API gateway docs here.
Related
I have a lambda function in AWS inside a VPC. I want to attach http handler (function URL).
The problem is, if I enable the function URL then it creates a public endpoint.
Alternatives I don't want to use
enable AWS_IAM security (then the caller will need to use AWS SKD and get token and all)
API gateway trigger (I am already using API gateway as proxy to kubernetes Ingress, I don't want to diverge that)
ALB (I am already using k8s ingress, which creates ALB, so I want the proxy to be created manually by code, not using lambda configuration)
Is there a way we can create AWS Lambda function URL but it should be accessible only within VPC without involving AWS SKD? (like wget URL)
In our org, we ended up going with an internal-only ALB and we enabled MultiValueQueryStringParameters to pass data into the Lambda function and to execute it. This is the only way I could find to provide an internal-only URL that I could further protect with a security group. I couldn't figure out how to make Lambda URLs internal-only.
I looked into this for a similar use-case, eventually I went with a direct lambda Invoke from the SDK, using the RequestResponse InvocationType to obtain the response payload. This suited my needs, but it might not suit your case.
InvokeResponse response = await lambdaClient.InvokeAsync(new InvokeRequest() {
FunctionName = "LambdaFunctionName",
InvocationType = InvocationType.RequestResponse,
Payload=data
});
I have a lambda function exposed via API gateway but when I try to request it using fetch it is saying that I am forbidden to access it. How do I allow my function to call another function via API gateway?
There can be multiple reasons for it.
Check whether your API gateway endpoint is open or not. While specifying trigger for lambda you must have selected one option for security. You can edit this in API gateway Method Execution tab under Authorization Settings, select Authorization : None and API key required: false
You might not have enabled CORS on your api and due to that your api is not available on cross regions.
Your api gateway is not having access to lambda function. You can do that by attaching IAM role to your API gateway API which can trigger your lambda function.
Is it possible to have a wildcard route defined and have the uri passed to the lambda for processing?
You can do this by creating a proxy resource in API Gateway with a greedy path variable {proxy+} in resource path. The event object in the lambda used for integration should get the actual path which you can then process.
This blog post here describes how to do it.
I have a lambda function that I'd like to trigger via HTTP request.
When I click add trigger to a lambda function, I get an API Gateway API set up with:
method: ANY
Great. Now, when viewing this lambda function, I see a trigger has been configured.
However, I would like to restrict the trigger to only allow POST requests.
So I deleted the API Gateway method ANY, and created a new method POST, under the same resource, using an integration type of Lambda Function. I select my region, and sure enough, my existing lambda function is autocompleted.
However, when I view the triggers tab on the lambda function itself, it shows that there are no triggers.
What am I missing?
If you need flexible control of the API, I would suggest to use the API Gateway console to mange your API. Lambda triggers should only be used for simple use-cases - API methods configured through API Gateway will not show up in the Lambda triggers list.
I already had an API Gateway API as the trigger for my AWS Lambda function. However when I tried to add another API as a trigger to the same AWS Lambda, it threw an error saying that
There was an error creating the trigger: An integration is already present on this method.
Even when I delete the trigger already present from the configuration window of Lambda, it still shows that the trigger is present.
How can I add multiple API Gateway APIs as triggers for the same lambda function ?
You can setup it via API Gateway console.
Create the Lambda function via Lambda without providing a trigger
Go to API Gateway Console
Create an API.
Create a resource and method
Select the Lambda function you want to trigger by the method
Create an other API/method
Select the Lambda function you want to trigger by the method
Since you are creating the trigger/integration via API Gateway Console, API Gateway will setup the proper permission to allow API Gateway to invoke your Lambda function on multiple APIs/methods.
In the API Gateway, we cannot make entries with the same resource name. When you have created a trigger it's already created and again you are trying to create another one. So we have to clear the previous one and then try again or else we can update it going into the API Gateway interface.