Skip to content

Instantly share code, notes, and snippets.

@myun2
Last active August 8, 2018 10:01
Show Gist options
  • Save myun2/072972ff24c4f9bfd8011b973b9fb153 to your computer and use it in GitHub Desktop.
Save myun2/072972ff24c4f9bfd8011b973b9fb153 to your computer and use it in GitHub Desktop.
Event Store Serverless
# package directories
node_modules
jspm_packages
# Serverless directories
.serverless
'use strict';
const AWS = require('aws-sdk'),
db = new AWS.DynamoDB(),
TABLE_NAME = 'event-store';
const indexQueryParams = (organization) => (
{
TableName: TABLE_NAME,
Item: event
}
);
module.exports.create = (event, context, callback) => {
console.log(event)
db.put(putParams(event), (err, data) => {
if (err) {
callback(err);
}
else {
callback(null, { statusCode: 200, body: 'OK' });
}
});
};
service: event-store
provider:
name: aws
runtime: nodejs6.10
region: ap-northeast-1
profile: serverless-deploy
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:ap-northeast-1:*:table/event-store*"
resources:
Resources:
ActivitiesDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: event-store
AttributeDefinitions:
-
AttributeName: resource_name
AttributeType: S
-
AttributeName: resource_id
AttributeType: S
KeySchema:
-
AttributeName: resource_name
KeyType: HASH
-
AttributeName: resource_id
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
functions:
root:
handler: events.create
events:
- http:
path: /events
method: post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment