-
-
Save niravvarma/6f29b14a9df723746b1cc104f435ac6c to your computer and use it in GitHub Desktop.
serverless-framework-app
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'); | |
module.exports.create = (event, context, callback) => { | |
const timestamp = new Date().getTime(); | |
const data = JSON.parse(event.body); | |
var params = { | |
TableName: process.env.TABLE_NAME, | |
Item: { | |
"customer_id": data.customer_id, | |
"created_timestamp": timestamp | |
} | |
}; | |
var dynamodbDocClient = new AWS.DynamoDB.DocumentClient(); | |
dynamodbDocClient.put(params, function(err, data) { | |
if (err) callback(Error(err)) | |
else callback(null, {statusCode: 200, body: JSON.stringify(params)}); | |
}); | |
} |
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
org: fernando # Replace this with your organization | |
app: customers-demo-sam | |
service: api | |
frameworkVersion: '>=1.50.0 <2.0.0' | |
provider: | |
name: aws | |
runtime: nodejs8.10 | |
memorySize: 512 | |
timeout: 10 | |
environment: | |
TABLE_NAME: customerTable-${opt:stage, 'dev'} | |
iamRoleStatements: | |
- Effect: Allow | |
Action: | |
- dynamodb:PutItem | |
Resource: "arn:aws:dynamodb:us-east-1:*:table/customerTable-${opt:stage, 'dev'}" | |
functions: | |
newCustomer: | |
handler: create.create | |
memorySize: 512 | |
timeout: 10 | |
events: | |
- http: | |
path: /create | |
method: post | |
resources: | |
Resources: | |
customerTable: | |
Type: 'AWS::DynamoDB::Table' | |
Properties: | |
TableName: customerTable-${opt:stage, 'dev'} | |
AttributeDefinitions: | |
- AttributeName: customer_id | |
AttributeType: S | |
KeySchema: | |
- AttributeName: customer_id | |
KeyType: HASH | |
ProvisionedThroughput: | |
ReadCapacityUnits: 1 | |
WriteCapacityUnits: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment