Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
| [Aws Scheduled Weather](https://github.com/serverless/examples/tree/master/aws-node-scheduled-weather) <br/> Example of creating a function that runs as a cron job using the serverless `schedule` event through pulling weather and sending an email daily. | nodeJS |
| [Aws Serve Dynamic Html Via Http Endpoint](https://github.com/serverless/examples/tree/master/aws-node-serve-dynamic-html-via-http-endpoint) <br/> Hookup an AWS API Gateway endpoint to a Lambda function to render HTML on a `GET` request | nodeJS |
| [Aws Serve Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-node-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint | nodeJS |
| [Aws Simpledb Example](https://github.com/serverless/examples/tree/master/aws-node-simpledb) <br/> Serverless REST API with Simpledb | nodeJS |
| [Aws Single Page App Via Cloudfront](https://github.com/serverless/examples/tree/master/aws-node-single-page-app-via-cloudfront) <br/> Demonstrating how to deploy a Single Page Application with Serverless | nodeJS |
| [Serverless Single Page App Plugin](https://github.com/serverless/examples/tree/master/aws-node-single-page-app-via-cloudfront/serverless-single-page-app-plugin) <br/> A plugin to simplify deploying Single Page Application using S3 and CloudFront | nodeJS |
| [Aws Node Stripe Integration](https://github.com/serverless/examples/tree/master/aws-node-stripe-integration) <br/> This example for Stripe integration using AWS Lambda and API Gateway. | nodeJS |
Expand Down
2 changes: 2 additions & 0 deletions aws-node-simpledb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.serverless
21 changes: 21 additions & 0 deletions aws-node-simpledb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Serverless REST API with Simpledb

[SimpleDB](https://aws.amazon.com/simpledb/) is an AWS NoSQL key-value storage service without a web console.

SimpleDB consists of domains (tables) and items (rows). Each domain can be up too 10GB, each item can have up to 256 attributes (columns), each up to 1024 bytes big. So each item can store 262.144 kilobytes of data. [Details](http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/SDBLimits.html).

As you see it's mainly for storing tiny pieces of data. A use case could include: storing pointers to S3 objects, querying SimpleDB is significantly faster than sorting through S3.

It's also basically free, with 1 GB of data transfer out and 1 GB of storage costing less than a nickel a month. [Details](https://aws.amazon.com/simpledb/pricing/).

The examples in `codes/` includes:

- domain.js
- createdomain
- deletedomain

- item.js
- createitem
- updateitem
- deleteitem
- select
82 changes: 82 additions & 0 deletions aws-node-simpledb/codes/domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';

const AWS = require('aws-sdk'); // eslint-disable-line import/no-extraneous-dependencies

// CREATE DOMAIN
// EXPECTS DATA IN FORMAT:
// domain/ POST
/*
{
domain: <domain>
}
*/
module.exports.create = (context, event, callback) => {
const data = event;

if (!data.domain) {
console.log('Create domain failed, domain not provided');
callback(new Error('Couldn\'t create domain.'), null);
return;
}

const params = {
DomainName: data.domain,
};

// query+callback
const simpledb = new AWS.SimpleDB();
simpledb.createDomain(params, (err) => {
if (err) {
console.error(err);
callback(new Error('Couldn\'t create domain.'));
return;
}

const response = {
statusCode: 200,
body: JSON.stringify(params),
};

callback(null, response);
});
};


// DELETE DOMAIN
// EXPECTS DATA IN FORMAT:
// domain/ DELETE
/*
{
domain: <domain>
}
*/
module.exports.delete = (context, event, callback) => {
const simpledb = new AWS.SimpleDB();

const data = event;

if (!data.domain) {
console.log('Delete domain failed, domain not provided');
callback(new Error('Couldn\'t delete domain.'), null);
return;
}

const params = {
DomainName: data.domain,
};

simpledb.deleteDomain(params, (err) => {
if (err) {
console.error(err);
callback(new Error('Couldn\'t delete domain.'));
return;
}

const response = {
statusCode: 200,
body: JSON.stringify(params),
};

callback(null, response);
});
};
Loading