Last active
August 8, 2018 10:01
-
-
Save myun2/072972ff24c4f9bfd8011b973b9fb153 to your computer and use it in GitHub Desktop.
Event Store Serverless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# package directories | |
node_modules | |
jspm_packages | |
# Serverless directories | |
.serverless |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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' }); | |
} | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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