Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 3.28 KB

services-apigateway-blueprint.md

File metadata and controls

58 lines (39 loc) · 3.28 KB

Create a simple microservice using Lambda and API Gateway

In this tutorial you will use the Lambda console to create a Lambda function, and an Amazon API Gateway endpoint to trigger that function. You will be able to call the endpoint with any method (GET, POST, PATCH, etc.) to trigger your Lambda function. When the endpoint is called, the entire request will be passed through to your Lambda function. Your function action will depend on the method you call your endpoint with:

  • DELETE: delete an item from a DynamoDB table
  • GET: scan table and return all items
  • POST: Create an item
  • PUT: Update an item

Create an API using Amazon API Gateway

Follow the steps in this section to create a new Lambda function and an API Gateway endpoint to trigger it:

To create an API

  1. Sign in to the AWS Management Console and open the AWS Lambda console.

  2. Choose Create Lambda function.

  3. Choose Blueprint.

  4. Enter microservice in the search bar. Choose the microservice-http-endpoint blueprint and then choose Configure.

  5. Configure the following settings.

    • Namelambda-microservice.
    • RoleCreate a new role from AWS policy templates.
    • Role namelambda-apigateway-role.
    • Policy templatesSimple microservice permissions.
    • APICreate a new API.
    • API type - REST API.
    • SecurityOpen.

    Choose Create function.

When you complete the wizard and create your function, Lambda creates a proxy resource named lambda-microservice under the API name you selected. For more information about proxy resources, see Configure proxy integration for a proxy resource.

A proxy resource has an AWS_PROXY integration type and a catch-all method ANY. The AWS_PROXY integration type applies a default mapping template to pass through the entire request to the Lambda function and transforms the output from the Lambda function to HTTP responses. The ANY method defines the same integration setup for all the supported methods, including GET, POST, PATCH, DELETE and others.

Test sending an HTTPS request

In this step, you will use the console to test the Lambda function. In addition, you can run a curl command to test the end-to-end experience. That is, send an HTTPS request to your API method and have Amazon API Gateway invoke your Lambda function. In order to complete the steps, make sure you have created a DynamoDB table and named it "MyTable". For more information, see Create a DynamoDB table with a stream enabled

To test the API

  1. With your lambda-microservice function still open in the console, choose Configure test events from the Select a test event dropdown list.

  2. Replace the existing text with the following:

    {
    	"httpMethod": "GET",
    	"queryStringParameters": {
    	"TableName": "MyTable"
        }
    }
    
  3. After entering the text above choose Create.

  4. Choose the event and choose Test.