Skip to content

Latest commit

 

History

History

apigw-lambda-sls

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Amazon API Gateway REST API with AWS Lambda proxy integration

This pattern in Serverless Framework offers a boilerlate to generate an Amazon API Gateway REST API endpoint with a greedy proxy ("{proxy+}") and "ANY" method from the specified path, meaning it will accept by default any method and any path. The Lambda function, provided in TypeScript, only returns the path.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-lambda-sls.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/serverless-patterns
  2. Change directory to the pattern directory its source code folder:

        cd serverless-patterns/apigw-lambda-sls
  3. From the command line, use npm to install the development dependencies:

    npm install
  4. To deploy from the command line use the following:

    serverless deploy --verbose

    The above command will deploy resources to us-east-1 region by default. You can override the target region with --region <region> CLI option, e.g.

    serverless deploy --verbose --region us-west-2
  5. Note the ServiceEndpoint output from the deployment process. You will use this value for testing.

Testing

  1. After deployment, the output shows the API Gateway URL with the Lambda integration, for example: ServiceEndpoint: https://<random-id>.execute-api.us-east-1.amazonaws.com/prod/.
  2. Accessing the URL in a browser, you see: Hello Serverless Citizen, your happy path is: "/".
  3. This page logs any path you type after "/". You can use this as a starting point as a general purpose endpoint for various types of applications. That said, you can try adding extra path to the ServiceEndpoint URL and confirm it being reported back to the user, e.g. navigating to <ServiceEndpoint>/aaa/bbb/ccc URL results in Hello Serverless Citizen, your happy path is: "/aaa/bbb/ccc" returned to the user.

Cleanup

  1. Delete the stack

    serverless remove --verbose
  2. Confirm the stack has been deleted

    aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'apigw-lambda-sls-prod')].StackStatus"

    Expected output

    [
        "DELETE_COMPLETE"
    ]

    NOTE: You might need to add --region <region> option to AWS CLI command if you AWS CLI default region does not match the one, that you used for the Serverless Framework deployment.


Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0