How to use default request templates when using the serverless framework? - serverless-framework

I understand that I need to specify a request template for the API gateway in order to gain access to the request headers. The Serverless docs say:
"Serverless ships with the following default request templates you can use out of the box:"
The default templates look like they provide access to what I want (i.e. request headers), but how do you tell Serverless to use them?

The "default request templates you can use out of the box" are referring to a lambda integration, not a "default" integration, where you leave the parameter blank. If no integration is defined, then it is the default integration. So, under http, add "integration: lambda".
However, that being said, you should still have access to the headers when you do not specify the integration.
Lambda Integration
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-event-before-customization
functions:
create:
handler: posts.create
events:
- http:
path: posts/create
method: post
integration: lambda
Default Integration
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-proxy-event-default
functions:
index:
handler: handler.hello
events:
- http: GET hello

Related

Defining API path with query string Serverless HTTP API (API Gateway v2)

How can I define the path in serverless.yml with more than one query parameter using HTTP API (API Gateway v2) so that the endpoint looks like the following:
https://example.com/rest/endpoint?id=$id&tag=$tag
serverless.yml
dfsPostback:
handler: handlers/result.main
events:
- httpApi:
path: /dfs-pingback // need help here
method: get
I tried with
path: /dfs-pingback?id={id}&tag={tag}
deployment failed
There is no need to specify the query parameters in the path. You should be able to access all passed query params in your event handler.

How to configure serverless framework HttpApi Authorizer for custom lambda authorizer

In the documentation there is information on how to configure authorizers such as Cognito:
https://www.serverless.com/framework/docs/providers/aws/events/http-api#jwt-authorizers
And here is a copy of it:
httpApi:
authorizers:
someJwtAuthorizer:
identitySource: $request.header.Authorization
issuerUrl: https://cognito-idp.${region}.amazonaws.com/${cognitoPoolId}
Does anyone know how to configure for custom lambda jwt authorizer I have coded myself?
I only achieved it using a previously created JWT Authorizer for httpApi, but must be similar with a custom Lambda Authorizer (never used one)
- httpApi:
method: any
authorizer: # https://github.com/serverless/serverless/issues/7598
# Provide both type and authorizerId
type: COGNITO_USER_POOLS # TOKEN or REQUEST or COGNITO_USER_POOLS, same as AWS Cloudformation documentation
id: <AUTHORIZER ID> # or authorizer name "name: my-lambda"
scopes: # Optional - List of Oauth2 scopes when type is COGNITO_USER_POOLS
- my-resource-server/my-grant-type
path: /{proxy+}
More on this issue here:
AWS HTTP API: Support IAM and Lambda authorizers #8210
feat(AWS HTTP API): Add support for custom Lambda authorizers #9192
Check out the Serverless docs for API Gateway, which show several examples of using custom authorizers.

Change API Gateway Name when using Serverless Framework

The Serverless framework has made it very easy for developers to create an API gateway connected to a lambda function. like this
hello:
name: hello-handler
description: blablabla
handler: /lambda-functions/hello-handler.handler
role: HelloRole
package:
include:
- lambda-functions/hello-handler.js
events:
- http: GET hello
My question is how can I change the name of the API gateway that is going to be created?
Based on the doc, this should do the trick.
provider:
...
apiName: custom-api-name # Use a custom name for the API Gateway API

AWS API Gateway : route error

I created my API in EC2 instance of AWS. when I'm deploying my API in to AWS Api gateway. API Gateway provided me with a link. When I used that same link in postman to access my API, I'm getting the following error, despite providing IAM credentials.
The Error I'm facing is
{
"message": "No method found matching route / for http method GET."
}
I had the same problem and solved it. The problem is in the Invoke URL you're using. To fix this, please correct path: check the Deployment API link + double check what method you want to call.
You may need to add some more path variables after "/". E.g., "test", whatever, so path finishes with method you'd like to invoke.
I created test project for you, please see screenshot with example. So, in order for script to execute math operation, e.g. "add", you add "/math/add", not default invoke URL:
Good luck!
Check the "Auth" section of your method request in the API gateway.
I had the same response until I set Auth to "AWS_IAM"

WSO2 API Manager: Error adding test API (api with only root context)

Our service provides a simple test API:
GET /api/test/v1 which simply returns "Test Success"
Trying to add this to the WSO2 API Manager version 1.8.
Name: test
Context: test
Version: v1
Visibility: Public
Now what should be added under Resources? As the API does not have any sub-resources, tried adding as:
URL Pattern: /
Resource Name: /
When clicked "Implement", got the error "Error while adding Swagger Definition for test-v1"
Please suggest what is the right input for "Resources" in this case (where API has only a root context)
Leave for default resource pattern. This will enable all HTTP verbs (ie: GET/PUT/POST/DELETE/OPTIONS) to accept all resource patterns.
Eg: URL Pattern: /*