Skip to content

Commit 8d8196d

Browse files
authored
Added section on Variable Scoping [DOC-1065].md
1 parent a8b5a9d commit 8d8196d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/connections/functions/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ Functions let you create your own sources and destinations directly within your
1212
## What can you do with Functions?
1313
Functions can help you bring external data into Segment ([Source functions](/docs/connections/functions/source-functions)) and send data in Segment out to external destinations ([Destination functions](/docs/connections/functions/destination-functions)). Use [Insert functions](/docs/connections/functions/insert-functions) to transform data before it reaches your downstream destinations. Functions are scoped to your specific workspace. If you're a technology partner and want to build a new integration and publish it in Segment's catalog, see the [Developer Center documentation](/docs/partners/).
1414

15+
### Variable scoping in Functions
16+
Functions are powered by AWS Lambda functions on the backend. This means you will need to declare any settings variables you create in the function handler rather than globally in your function.
17+
18+
- For Source functions, the handler is onRequest().
19+
- For Destination functions and Insert functions, the handler is event-specfic. For example onTrack(), onIdentify(), etc.
20+
21+
If you declare functions globally in your function code, you risk leaking those settings values across function instances if you have more than one per function codebase. Make sure that you scope settings to the handler functions and pass those settings values as arguments to any helper functions that may need them to ensure context remains scoped to each function instance.
22+
23+
Learn more about this at in the [AWS Documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html#:~:text=Avoid%20global%20variables,static%20initialization%20performance){:target="_blank"}.
24+
1525
#### Source functions
1626
Source functions receive external data from a webhook and can create Segment events, objects, or both. Source functions have access to the full power of JavaScript so you can validate and transform the incoming data and even make external API requests to annotate your data.
1727

@@ -54,4 +64,4 @@ IP Allowlisting uses a NAT gateway to route outbound Functions traffic from Segm
5464

5565
IP Allowlisting is available for customers on Business Tier plans.
5666

57-
To learn more, visit [Segment's IP Allowlisting documentation](/docs/connections/destinations/#ip-allowlisting).
67+
To learn more, visit [Segment's IP Allowlisting documentation](/docs/connections/destinations/#ip-allowlisting).

0 commit comments

Comments
 (0)