Create and Publish an AWS Lambda API¶
When using AWS Lambda, you can execute your code without having to manage or provision servers. For more information on AWS Lambda, see What is AWS Lambda?.
Follow the steps below to create and publish an AWS Lambda API:
Step 1 - Design a REST API¶
Sign in to the API Publisher Portal
Click CREATE API and then click Design a New REST API.
Enter the API details and click CREATE.
You do not need to enter the Endpoint during the initial process of creating the API. For more information on the possible API details that you can add, see Create a REST API
Now, you have created a new REST API successfully.
Step 2 - Add an AWS Lambda endpoint¶
- Click Endpoints to navigate to Endpoints page.
Navigate to the AWS Lambda endpoint type and click ADD.
Select the preferred Access Method
AWS SDK needs AWS credentials including the AWS region to invoke AWS Lambda functions. The access method defines as to how you provide those AWS credentials. You can provide AWS credentials and the AWS region manually by selecting the Using stored AWS credentials method. But if WSO2 API Manager is running on an Amazon EC2 instance, you can select the Using IAM role-supplied temporary AWS credentials method.
Note that this option can only be used if the API-M instance and the Lambda function belong to the same AWS account.
When using the IAM role-supplied temporary AWS credentials method, you need to attach an IAM role so that it can grant permission to applications running on the Amazon EC2 instance. For more information on attaching an IAM role to EC2, see Using an IAM Role to Grant Permissions to Applications Running on Amazon EC2 Instances
You will get an error message if you have not set the Access Method properly.
Step 3 - Map function-ARNs to resources¶
For more information on ARNs, see Amazon Resource Names (ARNs).
- Click Resources to navigate to the Resources page.
Configure the resources.
By default, the API will have five resources with
/*as the URL pattern.
Under AWS Lambda Settings, select or type Amazon Resource Name (ARN) for the resource.
You can select already created AWS Lambda functions that are listed in the autocomplete box.
Optionally, change the AWS SDK Client Execution Timeout by changing the Set Timeout option. The default AWS SDK Client Execution Timeout is 50 seconds.
- Min Timeout - 1 second
- Max Timeout - 15 minutes
Parameter mapping (path, query, and header) is not yet supported and you have to add these parameters to the payload before you send it.
Step 4 - Publish the AWS Lambda API¶
- Click Lifecycle to navigate to the API lifecycle.
Click PUBLISH to publish the API to the API Developer Portal.
You have successfully published the AWS Lambda API.Top