DynamoDB

Amazon DynamoDB is a fully managed NoSQL database service

provides fast and predictable performance with seamless scalability.

 DynamoDB offers encryption at rest, which eliminates the operational burden and complexity involved in protecting sensitive data.
Create database tables that can store and retrieve any amount of data, and serve any level of request traffic.

 AWS Management Console to monitor resource utilization and performance metrics.




Select DynamoDB from the services menu



Create a simple table to store data

Create a simple Guestbook table

Once you create table it will be available via ARN (Amazon Resource Number)


Need to add permissions to role to access DynamoDB


Use IAM (Identity Access Management) to add policies to existing role


IAM functionality limited but you can add policies to existing roles


Select Lambda_basic_execution 



Add inline policy



Search for Dynamo and select full access 


Select DynamoDB as a service



Configure policy for full access


Click on Review Policy


Enter a policy name and create policy


Your role now has permissions to access your DynamoDB tables



Now we can create the dynamoWrite function to put data into our table

dynamo Write




console.log('Starting Function');

const  AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

exports.handler = function(event, context, callback) {
    var params = {
        Item: {
            date: Date.now(),
            message: "I love your website!"
        },
        TableName: 'guestbook'
        };
        docClient.put(params, function(err, data){
        if (err){
            callback(err, null);
        }else{
            callback(null, data);
        }
        });
        }


Now check your dynamoDB table for the record you just created


click on the table name




Click on the record just created



Use the Date key for your Query String lookup

Create a new Lambda function Called DynamoQuery

DynamoQuery


console.log('Starting Function');

const  AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});

exports.handler = function(event, context, callback) {
   
        var params = {
        TableName: 'guestbook',
        Key: {
            "date": 1550953270989
        }
        };
        docClient.get(params, function(err, data){
        if (err){
            callback(err, null);
        }else{
            callback(null, data);
        }
        });
        }



No comments:

Post a Comment

To All, If you are working in starter accounts please move the work into the classroom account so I can review. For the previous ...