https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
l

loud-london-22241

07/14/2023, 9:45 AM
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

fresh-football-47124

07/14/2023, 3:34 PM
how are you fetching the features?
l

loud-london-22241

07/17/2023, 12:04 AM
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

fresh-football-47124

07/17/2023, 12:05 AM
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

loud-london-22241

07/17/2023, 12:05 AM
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

fresh-football-47124

07/17/2023, 12:07 AM
AB tests are fined with feature rules, so nothing special needs to be done other than adding a rule to a feature
l

loud-london-22241

07/17/2023, 12:07 AM
current attributes i am setting are
Copy code
id: ,
            ip: ,
            loggedIn: ,
            sessionId: ,
            platformType: ,
            appVersion: ,
            correlationId: ,
            httpMethod: ,
            country:
f

fresh-football-47124

07/17/2023, 12:08 AM
you’ll also want to add something to your trackingCallback method
l

loud-london-22241

07/17/2023, 12:08 AM
thanks heaps 🙏
f

fresh-football-47124

07/17/2023, 1:42 AM
btw, you’ll also want to set a matching set of attributes from within GrowthBook, so you can target correctly
l

loud-london-22241

07/17/2023, 1:43 AM
yes I adjusted the attributes and removed the one i do not use and added the one fits our use case
76 Views