Build a Hello World REST API with Lambda proxy integration
- Create a “Hello, World!” Lambda function
-
Build a “Hello, World!” API
- Sign in to the API Gateway console at https://console.aws.amazon.com/apigateway.
- If this is your first time using API Gateway, you see a page that introduces you to the features of the service. Under REST API, choose Build. When the Create Example API popup appears, choose OK.
If this is not your first time using API Gateway, choose Create API. Under REST API, choose Build. - Create an empty API as follows:
- Under Create new API, choose New API.
- Under Settings:
- For API name, enter
LambdaSimpleProxy
. - If desired, enter a description in the Description field; otherwise, leave it empty.
- Leave Endpoint Type set to Regional.
- For API name, enter
- Choose Create API.
- Create the
helloworld
resource as follows:- Choose the root resource (/) in the Resources tree.
- Choose Create Resource from the Actions dropdown menu.
- Leave Configure as proxy resource unchecked.
- For Resource Name, enter
helloworld
. - Leave Resource Path set to /helloworld.
- Leave Enable API Gateway CORS unchecked.
- Choose Create Resource.
- In a proxy integration, the entire request is sent to the backend Lambda function as-is, via a catch-all
ANY
method that represents any HTTP method. The actual HTTP method is specified by the client at run time. TheANY
method allows you to use a single API method setup for all of the supported HTTP methods:DELETE
,GET
,HEAD
,OPTIONS
,PATCH
,POST
, andPUT
.To set up theANY
method, do the following:- In the Resources list, choose /helloworld.
- In the Actions menu, choose Create method.
- Choose ANY from the dropdown menu, and choose the checkmark icon
- Leave the Integration type set to Lambda Function.
- Choose Use Lambda Proxy integration.
- From the Lambda Region dropdown menu, choose the region where you created the
GetStartedLambdaProxyIntegration
Lambda function. - In the Lambda Function field, type any character and choose
GetStartedLambdaProxyIntegration
from the dropdown menu. - Leave Use Default Timeout checked.
- Choose Save.
- Choose OK when prompted with Add Permission to Lambda Function.
-
Deploy the API in the API Gateway console
- Choose Deploy API from the Actions dropdown menu.
- For Deployment stage, choose [new stage].
- For Stage name, enter
test
. - If desired, enter a Stage description.
- If desired, enter a Deployment description.
- Choose Deploy.
- Note the API’s Invoke URL.
- Use browser and cURL to test an API with Lambda proxy integration
To testGET
requests using only query string parameters, you can type the URL for the API’shelloworld
resource into a browser address bar. For example: https://r275xc9bmd
.execute-api.us-east-1
.amazonaws.com/test/helloworld?name=John&city=Seattle
Comments are closed, but trackbacks and pingbacks are open.