Skip to content

Instantly share code, notes, and snippets.

@jtsaito
Last active September 19, 2018 10:26
Show Gist options
  • Save jtsaito/ce6f659a78ed47c61237b3c59827444c to your computer and use it in GitHub Desktop.
Save jtsaito/ce6f659a78ed47c61237b3c59827444c to your computer and use it in GitHub Desktop.
AWS Lambda Handler for node8.10 with DynamoDB client call

Exmaple handler given a DynamoDB table your-table with hash key uuid.

const AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
const dynamo = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

exports.handler = async (event) => {
    //console.log('Received event:::', JSON.stringify(event));
    
    const params = {
      TableName : 'your-table',
      Item: {
        'uuid': '4711',
        'lala': event.queryStringParameters.lala
      }
    };
    
    let result;
    try {
      result = await dynamo.put(params).promise();
    } catch(error) {
     console.log('error: ' + error);
    }
    
    console.log('result: ' + JSON.stringify(result));
    
    return {};
};

GET

  params = {
    TableName: 'your-table',
    Key: {
      'uuid': '4893458348957'
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment