Provide access to data via GET request
This commit is contained in:
parent
49926de6f5
commit
7cf8c6bb3b
2 changed files with 36 additions and 0 deletions
28
handler.js
28
handler.js
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue