Skip to content

Moesif/moesif-middy-serverless-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moesif-middy-serverless-example

This examples demonstrates how to use Moesif AWS Lambda middleware for Node.js with Middy and Serverless Framework.

Overview

This example builds and deploys a simple HTTP API to AWS using Serverless right from your terminal. The API has a single valid endpoint greet/ that expects POST requests. A valid POST request body looks like the following:

{
    "greetingsMessage": "Good evening!",
    "greeterName": "Alex"
}

The example uses the following Middy middlewares:

Repository structure

.
├── handler.js
├── package.json
├── README.md
└── serverless.yml

The AWS Lambda function and the API logic lives inside handler.js. The serverless.yml file describes your Serverless app's infrastructure. For more information, see Serverless.yml Reference.

Before you begin

Before running this example, make sure you have performed the following steps:

CommonJS and ECMAScript modules

This example uses ECMAScript modules to comply with the latest 5.x version of Middy.

If you want to run this example using CommonJS, use Middy version 4.x. Additionally, you must make the following adjustments:

  1. Remove "type": "module" from the package.json file.
  2. Change the import and export statements to CommonJS-style imports and exports.

How to run the example

  1. Clone this repository and enter its directory:

    cd moesif-middy-serverless-example
  2. Specify your Moesif Application ID in the .env file:

     MOESIF_APPLICATION_ID=YOUR_MOESIF_APPLICATION_ID
  3. Install the dependencies:

    npm install
  4. Then deploy with Serverless:

    serverless deploy

    For a successful deployment, the deploy command generates an output similar to the following:

    Deploying "moesif-middy-serverless" to stage "dev" (us-east-1)
    
    ✔ Service deployed to stack moesif-middy-serverless-dev (69s)
    
    endpoint: POST - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/greet
    functions:
    greetingsHandler: moesif-middy-serverless-dev-greetingsHandler (3.7 MB)
    
  5. Send requests to the API endpoint. In your Moesif Web Portal, you should see API traffic details show up.

How to Get Help

If you face any issues running this example, reach out to our support team or open an issue.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published