Skip to content

Instantly share code, notes, and snippets.

@patrickdronk
Created November 22, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickdronk/c95cd8eddeef1f482dc906316cfd0b2d to your computer and use it in GitHub Desktop.
Save patrickdronk/c95cd8eddeef1f482dc906316cfd0b2d to your computer and use it in GitHub Desktop.
const axios = require('axios');
const AWS = require('aws-sdk');
const region = 'eu-west-1'; // REGION SHOULD BE LIKE (eu-west-1)
const dynamodb = new AWS.DynamoDB({ region: region, apiVersion: '2012-08-10' });
exports.handler = async ({body}) => {
const {data} = await axios.post("https://847some2lk.execute-api.eu-west-1.amazonaws.com/live/register", body);
const item = {
Item: {
"sessionId": {
S: data.sessionId
},
"name": {
S: event.name
},
"start": {
S: Date.now().toString()
},
"numberOfLetters": {
N: data.nrOfLetters.toString()
},
"totalCharsGuessedRight": {
N: "0"
},
"score": {
N: "0"
}
},
TableName: 'sessions'
};
try {
await dynamodb.putItem(item).promise();
}
catch (err) {
return {
"statusCode": 500,
"headers": {
"Content-Type": "application/json"
},
"body": JSON.stringify(err.data),
"isBase64Encoded": false
};
}
return {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": JSON.stringify(data),
"isBase64Encoded": false
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment