Skip to content

Commit f965ed5

Browse files
chore(lambda): add documentation for SingletonLambda to README (#5996)
relates #5616 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 388c987 commit f965ed5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/@aws-cdk/aws-lambda/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ correct log retention period (never expire, by default).
182182
*Further note* that, if the log group already exists and the `logRetention` is not set, the custom resource will reset
183183
the log retention to never expire even if it was configured with a different value.
184184

185+
### Singleton Function
186+
187+
The `SingletonFunction` construct is a way to guarantee that a lambda function will be guaranteed to be part of the stack,
188+
once and only once, irrespective of how many times the construct is declared to be part of the stack. This is guaranteed
189+
as long as the `uuid` property and the optional `lambdaPurpose` property stay the same whenever they're declared into the
190+
stack.
191+
192+
A typical use case of this function is when a higher level construct needs to declare a Lambda function as part of it but
193+
needs to guarantee that the function is declared once. However, a user of this higher level construct can declare it any
194+
number of times and with different properties. Using `SingletonFunction` here with a fixed `uuid` will guarantee this.
195+
196+
For example, the `LogRetention` construct requires only one single lambda function for all different log groups whose
197+
retention it seeks to manage.
198+
185199
### Language-specific APIs
186200
Language-specific higher level constructs are provided in separate modules:
187201

packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ export interface SingletonFunctionProps extends FunctionProps {
3131
/**
3232
* A Lambda that will only ever be added to a stack once.
3333
*
34-
* The lambda is identified using the value of 'uuid'. Run 'uuidgen'
35-
* for every SingletonLambda you create.
34+
* This construct is a way to guarantee that the lambda function will be guaranteed to be part of the stack,
35+
* once and only once, irrespective of how many times the construct is declared to be part of the stack.
36+
* This is guaranteed as long as the `uuid` property and the optional `lambdaPurpose` property stay the same
37+
* whenever they're declared into the stack.
3638
*
3739
* @resource AWS::Lambda::Function
3840
*/

0 commit comments

Comments
 (0)