Giter Site home page Giter Site logo

lambda-sailthru's Introduction

lambda-sailthru

A lightweight AWS Lambda function that communicates with Sailthru.com API. This function will work with any Salthru endpoint by specifying the endpoint name in the JSON object provided to the function.

Includes Airbrake integration. To enable your Airbrake integration you must set the following deployment variables: AIRBRAKE_PROJECT_ID and AIRBAKE_PROJECT_KEY. If these variables are not provided Airbrake will not be enabled but the function will still make API requests.

Getting Started

  1. npm install -g node-lambda
  2. npm install
  3. Copy deploy.env.example to deploy.env
  4. Copy event.json.example to event.json
  5. Copy .env.example to .env
  6. To test the function locally: node-lambda run

Example

The following is an example of a JSON object lambda-sailthru expects. You will also find this example in event.json.example

{
  "apiType": "user",
  "apiKey": "INTERNAL_API_KEY",
  "postParams": {
    "id": "[email protected]",
    "key": "email",
    "vars": {
      "test": "true"
    }
  }
}

apiType: Sailthru endpoint

apiKey: This should match your SAILTHRU_LAMBDA_KEY provided in deploy.env

postParams: JS object that provides required Sailthru API parameters. See Sailthru API documentation for examples.

Deployment

If you installed node-lambda there are two options available

  1. node-lambda package

    Creates a compressed zip file that includes the main function and node_modules folder

  2. node-lambda deploy

    Automatically deploys the function to your AWS Lambda server. Requires AWS keys in .env to be updated with your credentials. See node-lambda documentation for more configuration options

AWS API Gateway Configuration

Incoming POST requests to Amazon API Gateway require configuring the endpoint's Integration Request. The following is an example mapping for POST requests with Content-Type: application/json

#set($allParams = $input.params())
{
"body" : $input.json('$'),
"params" : {
#foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
"$type" : {
    #foreach($paramName in $params.keySet())
    "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
        #if($foreach.hasNext),#end
    #end
}
    #if($foreach.hasNext),#end
#end
},
"context" : {
    "account-id" : "$context.identity.accountId",
    "api-id" : "$context.apiId",
    "api-key" : "$context.identity.apiKey",
    "http-method" : "$context.httpMethod",
    "user" : "$context.identity.user",
    "user-agent" : "$context.identity.userAgent",
    "request-id" : "$context.requestId",
    "resource-id" : "$context.resourceId",
    "resource-path" : "$context.resourcePath"
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.