Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Richard Hyatt
    @richardhyatt
    Richard Hyatt
    @richardhyatt
    just released vandium 2.7.2
    Will Borchardt
    @theborch
    hey @richardhyatt , coworker just shared vandium with our team, and wanted to let you know that the docs links on the site is borked s/main/README/
    also, kudos on the project and keeping it OSS
    Richard Hyatt
    @richardhyatt
    @theborch thanks - fixed the docs link
    vanerleo
    @vanerleo
    Hi, are there release notes for 3.0?
    found it :)
    Rodrigo Falcetta Laperuta
    @rflaperuta
    Hello, with vandium and Lambda Proxy, what is the proper way to validate a POST as follows:
    Content-type is:
    application/x-www-form-urlencoded
    Inside event object i get along with other parameters:
    body: 'userid=user@domain.com.br&password=abc@123'
    Rodrigo Falcetta Laperuta
    @rflaperuta
    Nvm, fount it! :-)
    On the same way Using SQLi protection + Lambda Proxy, i saw on the logs:
    * vandium - SQL Injection detected - EQUALS_WITH_COMMENT
    key = Accept-Language
    value = en-US,en;q=0.8,pt-BR;q=0.6,pt;q=0.4,es;q=0.2
    The header received is
    'Accept-Language': 'pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4',
    There is nothing wrong with it, is there a work around this issue without disabling the SQLi protection?
    Richard Hyatt
    @richardhyatt
    Lambda proxy support is in the 3.x branch (3.3 version) that will be released shortly - this is causing the SQLi detection to flag the 'Accept-Language' header
    Rodrigo Falcetta Laperuta
    @rflaperuta
    Thanks @richardhyatt, this points me to the fact I may have installed the master version while wanting the 3.x branch :-D
    vanerleo
    @vanerleo
    with vandium 3.x and serverless 1.4 , is it still possible to use a plain return out of the vandium wrapper ?
    Daniel Cooperman
    @dc00p
    Yes it is still possible
    'use strict';
    
    const vandium = require( 'vandium' );
    
    module.exports.hello = vandium( ( event ) => {
    
          const response = {
    
            statusCode: 200,
            body: JSON.stringify({
    
                message: 'Go Serverless v1.0! Your function executed successfully!',
                input: event,
            }),
          };
    
          return response;
    });
    Mikkel B. Jensen
    @mbejdk_twitter
    Hi guys.
    Do vandium.validation.configure( {lambdaProxy: true}); still work? I am getting vandium.validation.configure is not a function.
    Daniel Cooperman
    @dc00p

    Now use vandium.createInstance.

    Example:

    'use strict';
    
    const vandium = require( 'vandium' );
    
    exports.handler = vandium.createInstance( {
    
                lambdaProxy: true,
                validation: {
    
                    schema: {
    
                        body: {
    
                            firstName: vandium.types.string().min( 1 ).max( 250 ).required(),
    
                            lastName: vandium.types.string().min( 1 ).max( 250 ).required(),
    
                            age: vandium.types.number().min( 0 ).max( 130 ).required()
                        }
                    }
                }
            })
            .handler( function( event /*, context, callback*/ ) {
    
                // log event ?
                // console.log( JSON.stringify( event, null, 2 ) );
    
                // echo body portion
                return Promise.resolve( event.body );
            });

    See: https://github.com/vandium-io/vandium-node/blob/master/examples/lambda-proxy/handler.js

    Mikkel B. Jensen
    @mbejdk_twitter
    Thanks Daniel
    Mikkel B. Jensen
    @mbejdk_twitter
    @dc00p , do you have any suggestions on how to set Access-Control headers using vandium validation with Lambda Proxy? Can one specify the headers when vandium validation reports back?
    Daniel Cooperman
    @dc00p
    'use strict';
    
    const vandium = require( 'vandium' );
    
    exports.handler = vandium.createInstance( {
    
                lambdaProxy: true,
                validation: {
    
                    schema: {
    
                        headers: {
    
                            'Access-Control-...': vandium.types.string().required()
                            ...
                        }
    
                        body: {
    
                            ...
                        }
                    }
                }
            })
            .handler( function( event, context, callback ) {
    
                return {
    
                    headers: {
    
                        headerone: 'results?'
                    },
                    body: {}
                };
            });
    Mikkel B. Jensen
    @mbejdk_twitter

    Thanks @dc00p .

    However I am not able to change the headers on the response from a failed response. Check out the example below:

    'use strict'
    const vandium = require('vandium')
    
    exports.post = vandium.createInstance({
      lambdaProxy: true,
      validation: {
        schema: {
          body: {
            requirednumber: vandium.types.number().min(0).max(10).required()
          }
        }
      }
    })
    .handler(function (event, context, callback) {
    
      return {
    
        headers: {
          'Access-Control-Allow-Credentials': true,
          'Access-Control-Allow-Origin': '*'
        },
        body: {}
      }
    })

    Returns :
    { "statusCode": 422, "headers": {}, "body": "{\"type\":\"ValidationError\",\"message\":\"validation error: child \\\"requirednumber\\\" fails because [\\\"requirednumber\\\" is required]\"}" }
    So vandium basically skips the handler, when the validation fails and therefore does not set the headers?

    Daniel Cooperman
    @dc00p
    Correct
    Steve Schwarz
    @saschwarz
    Hi, I just heard about vandium are there any docs on how to deploy and run on lambda?
    Liz Rosa
    @erosa

    I'm using Vandium to process POST requests from API Gateway. I have a pretty vanilla implementation so far. The handler works as expected without validation, but as soon as I add the validation step, I get this error:

    {
      "type": "ValidationError",
      "message": "\"value\" must be an object"
    }

    My code looks more or less like this:

    const vandium = require('vandium');
    
    exports.handler = vandium.api()
      .protection({mode: 'fail'})
      .GET(event => {
      // ...
      })
      .POST({
        //validate
        body: {
          name: vandium.types.string().max(255).required(),
          id: vandium.types.number()
        }
      },
      (event, context) => {
        return new Promise((resolve, reject) => {
          conn.query('select * from user',
            (error, results, fields) => {
              if (error) {
                reject(error);
              } else {
                resolve(results);
              }
            });
        });
      });

    ...and the sample payload I'm using is {name: "Liz", id: "1234"}. The code does exactly what I want as long as I leave out the validation argument from the .POST() handler. Looks like a Joi error bubbling up through Vandium. Am I missing something here?

    Liz Rosa
    @erosa
    Never mind — my inexperience with Javascript and API programming is showing. Quote your JSON keys.
    Richard kim
    @Rkim01_twitter

    Hi there,

    the exact validation error brought me here (nothing in github issues)

    I'm using Vandium with Serverless Framework.
    According to Serverless Framework, requests templates application/json & application/x-www-form-urlencoded are supported out of the box.
    https://serverless.com/framework/docs/providers/aws/events/apigateway#default-request-templates

    On my vandium POST method handler,
    when i do :

    curl -X POST \
      http://localhost:3000/users \
      -H 'Content-Type: application/json' \
      -d '{ "firstName": "first", "lastName": "last", "age": 1 }'

    it works as expected

    but when i do :

    curl -X POST \
      http://localhost:3000/users \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -d 'firstName=first&lastName=last&age=1'

    it throws validation errors :

    {
        "type": "ValidationError",
        "message": "\"value\" must be an object"
    }

    here is the handler :

    module.exports.post = vandium.api()
        .callbackWaitsForEmptyEventLoop(false)
        .POST(
            {
                body: {
                    firstName: vandium.types.string().min(1).max(250).required(),
                    lastName: vandium.types.string().min(1).max(250).required(),
                    age: vandium.types.number().min(1).max(130)
                }
            },
            (event) => { ... });

    How could i solve this to support both content-types seamlessly?

    the API Gateway event is respectively showing
    body: '{ "firstName": "AHDOUHAGIUGAI", "lastName": "Dre", "age": 1 }',
    and
    body: 'firstName=test&lastName=azhdaa&age=2',

    Rayat Rahman
    @riotrah
    Not sure I have an answer for that yet - perhaps a PR is needed if no one responds.