1
0
Fork 0

Provide access to data via GET request

This commit is contained in:
Andrew Tomaka 2018-06-13 19:09:42 -04:00
parent 49926de6f5
commit 7cf8c6bb3b
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
2 changed files with 36 additions and 0 deletions

View file

@ -70,3 +70,31 @@ module.exports.check = (event, context, callback) => {
})
.catch(error => callback(error))
}
module.exports.data = (event, context, callback) => {
const zone = event.pathParameters.zone
const params = {
TableName: process.env.LIGHTSPEED_TABLE,
KeyConditionExpression: "#area = :area",
ExpressionAttributeNames: {
'#area': 'area',
},
ExpressionAttributeValues: {
':area': zone,
},
ScanIndexForward: false
}
if(event.queryStringParameters && event.queryStringParameters.latest) {
params.Limit = event.queryStringParameters.latest
}
ddb.query(params).promise()
.then(data => {
callback(null, { statusCode: 200, body: JSON.stringify(data.Items) })
})
.catch(error => {
console.log(error)
callback(error)
})
}

View file

@ -56,3 +56,11 @@ functions:
- schedule:
rate: rate(1 day)
enabled: true
data:
handler: handler.data
timeout: 10
events:
- http:
path: data/{zone}
method: get
cors: true