API Gateway 10.11 | Using API Gateway | Usage Scenarios | Custom Policy Extension | How Do I Invoke an AWS Lambda Function using Custom Extension?
 
How Do I Invoke an AWS Lambda Function using Custom Extension?
This use case explains how to invoke an AWS Lambda function using custom extension. The custom extension configured can be enforced in any of the policy stages and used during API processing.
The use case starts when you have an API that has to be enforced with a custom extension and ends when you successfully invoke the API with the custom extension enforced.
*To invoke an AWS Lambda function using custom extension
1. Create a Lambda function and ensure it is active.
For details on how to create an AWS Lambda function, see https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html.
2. Configure AWS alias.
For details on how to configure an AWS alias, see Configuring an AWS Alias.
3. Click APIs on the title navigation bar.
4. Click the required API.
The API details page appears.
5. Click Edit.
6. Select Policies.
7. Click Required Policy stage > Custom Extension.
This adds the custom extension policy where you can configure the required properties.
Click to open the policy properties section in a full page.
8. Provide the following information in the Conditions section, as required:
Property
Description
Condition
Conditions are used to specify when the policy has to be executed. You can add multiple conditions with logical operators.
Available values are:
*AND. API Gateway executes this policy when all the configured conditions comply in the respective policy stage
*OR. This is selected by default. API Gateway executes this policy when any one of the configured conditions complies.
Click Add Condition and provide the following information and click Add.
*Variable. Specifies the variable type with a syntax.
*Operator. Specifies the operator to use to relate variable and the value. You can select one of the following:
*Equals
*Equals ignore case
*Not equals
*Not equals ignore case
*Contains
*Exists
*Range
*Greater Than
*Less Than
*Value. Specifies a plain value or value with a syntax.
For details about the variables available in API Gateway, see Variables Available in API Gateway.
9. Click Custom Action.
10. Select AWS Lambda in the custom extension Type field.
11. Provide the following information in the AWS Lambda section, as required:
Property
Description
Function Name
Provide the AWS Lambda function name you want to invoke. As this property supports variable framework, you can use the available variables. For details about the variables available in API Gateway, see Variables Available in API Gateway.
Invocation Type
Specify the AWS invocation type, asynchronous or synchronous.
Available options are:
*RequestResponse (synchronous type)
*Event (asynchronous type)
AWS Alias
Provide the AWS alias configured for the AWS account.
Client Configuration
Provide the following client configuration details and click .
*Name. Start typing the client property name and select the required property from the type-ahead search results displayed.
API Gateway supports the following properties that you can configure: Socket timeout(ms), Connection timeout(ms), Request timeout(ms), Connection expiration timeout(ms), Maximum Connection idle time(ms), Client execution timeout(ms), Server error retry count, Enable throttle retries, Maximum client retry count, TCP send buffer size hints, TCP receive buffer size hints, Enable gzip requests, Enable Expect-Continue, Enable host prefix injection, Enable Keep-alive, Enable, Response metadata caching, Response metadata cache size, and Signature Algorithm.
*Value. Provide a value for the client property specified.
You can configure multiple properties.
For details about the supported client properties, see the following AWS documents:
12. Configure the custom properties of the custom extension as required.
For details about the custom extension properties and their descriptions, see Custom Extension Properties.
13. Click Save.
The API is saved with the added custom extension.
14. Invoke the API.
The applied custom extension invokes the AWS lambda function and processes as configured.