Hello everyone! trying to implement growthbook in ...
# ask-questions
l
Hello everyone! trying to implement growthbook in lambda function why do I get unknown feature. Seems like I am not configuring the feature flag correctly or this happen in non prod env. appreciate any help.
If anyone has good post around lambda integration that would be great.
f
how are you fetching the features?
l
Thanks @fresh-football-47124 its working now. Rollout was not configured properly. I am still trying to understand the best practice to use it in serverless lambda. from what i understood so far is fetch the features from the specific env and then pass them to the growth-book instance you just created.
Copy code
const response: AxiosResponse = await client.request({
            url: growthBookUrl,
            method: 'GET'
        })
        const { features } = response.data
        const growthBook = new GrowthBook({
            apiHost: growthBookUrl,
            clientKey: process.env.GROWTHBOOK_CLIENT_KEY ?? 'undefined',
            enableDevMode: process.env.GROWTHBOOK_DEV_MODE ? true : false,
            qaMode: process.env.GROWTHBOOK_QA_MODE ? true : false,
            features: (features ?? {}) as unknown as Record<string, FeatureDefinition>,
            log: (msg: string, ctx: GenericObject): void => {
                // do somthing
            },
            trackingCallback: (experiment: GenericObject, result: GenericObject): void => {
                  // do something
            }
        })
        await growthBook.refreshFeatures()
is it necessary to fetch all the features?
can i just define only the features i need
f
you can restrict features to a project or environment to return a smaller list
but since they’re just text, it shouldn’t be a big deal
l
make sense.
thanks. Next thing is to understand how to configure A/B testing or experiments
Do i need to push any data to growthbook first?
f
AB tests are fined with feature rules, so nothing special needs to be done other than adding a rule to a feature
l
current attributes i am setting are
Copy code
id: ,
            ip: ,
            loggedIn: ,
            sessionId: ,
            platformType: ,
            appVersion: ,
            correlationId: ,
            httpMethod: ,
            country:
f
you’ll also want to add something to your trackingCallback method
l
thanks heaps 🙏
f
btw, you’ll also want to set a matching set of attributes from within GrowthBook, so you can target correctly
l
yes I adjusted the attributes and removed the one i do not use and added the one fits our use case
117 Views