-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
32 lines (26 loc) · 1.04 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { LAUNCHDARKLY_APIKEY, DYNAMODB_TABLE } = process.env
const LaunchDarkly = require('ldclient-node')
const DynamoDBFeatureStore = require('ldclient-node-dynamodb-store')
const store = DynamoDBFeatureStore(DYNAMODB_TABLE)
// use daemon mode, and don't send events (for user-facing things)
const config = { featureStore: store, useLdd: true, sendEvents: false }
const ldclient = LaunchDarkly.init(LAUNCHDARKLY_APIKEY, config)
module.exports.hello = async (event) => {
console.log(JSON.stringify(event))
const key = event.queryStringParameters.key
const userKey = event.queryStringParameters.user
await ldclient.waitForInitialization()
const user = {
key: userKey,
country: event.headers['CloudFront-Viewer-Country']
}
// behind the scenes the LD client also makes a HTTPs request events.launchdarkly.com
// to register the user, which doesn't count towards the server connections
const showFeature = await ldclient.variation(key, user, true)
return {
statusCode: 200,
body: JSON.stringify({
showFeature
})
}
}