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.
Related
I am working with AWS API gateway and some of the API require URI request parameter (example). Is that I can simply call it by below URL? Any setting I need to be done in API gateway?
https://xxxxxxxxxx.execute-api.awsregion.amazonaws.com/my_stage/my_resource/target-policies/my_policy_name
Also what does Pattern: [\w+=,.#-]+ mean?
I am not sure if I understood your doubt 100%.
The link you provided is related to attach a policy on API Gateway.
The pattern your ask is the allowed characters for policy name.
If you question is about get URI parameters, for example via querystring, you can just post it to your API Gateway and use it on your method integration.
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 would like to proxy the incoming requests to different endpoints based on a request header received in the request.
In AWS API gateway, I can set up different endpoints as separate stage variables but at integration >> Endpoint URL setting, I would like to pick the stage variable based on the value of request header value.
For example:
if header value is brand-id: abc then request should be proxied to abc.test.com
if header value is brand-id: pqr then request should be proxied to pqr.test.com
I'm expecting something like this in "Endpoint URL" value:
http://${stageVariables.${method.request.header.brand-id}}/
Any help to achieve this would be appreciated.
AFAIK this is not possible on the API Gateway level. Option is to do the mapping on the lambda integration level.
You can use Lambda Proxy Integration to achieve the similar behavior:
Create your required set of API's.
Create a proxy endpoint that will pass everything to the Lambda Function.
Inside the Lambda Function decide on the basis of headers to call the respective endpoints and pass the required data from the payload you got.
Return the response as it is from the API you called.
You can use python's adapter pattern, or string parameter formatting to save yourself from the clutter of if and else conditions. You can also consider calling Lambdas directly from your proxy Lambda with RequestResponse invoke, that may save yourself some time caused by the extra layer of API Gateway.
When API Gateway is integrated with AWS Lambda function using Lambda proxy integration, the Lambda function will receive the HTTP request information in the event variable. An example of the event variable content can be found on AWS documentation here.
In the AWS example, the same value is appeared twice in the event variable but on different properties:
Property httpMethod and property requestContext.httpMethod are both having the same value GET
Property resource and property requestContext.resourcePath are both having the same value /{proxy+}
My question is, if I want to get the HTTP method and the resource path, which properties should I use?
You can use any of those. Whichever is more convenient and makes more sense in your code.
They are included both as event properties and as requestContext properties because they are semantically part of both.
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.