Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lambda): documentation for SingletonLambda in the README #5996

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ correct log retention period (never expire, by default).
*Further note* that, if the log group already exists and the `logRetention` is not set, the custom resource will reset
the log retention to never expire even if it was configured with a different value.

### Singleton Function

The `SingletonFunction` construct is a way to guarantee that a lambda function will be guaranteed to be part of the stack,
once and only once, irrespective of how many times the construct is declared to be part of the stack. This is guaranteed
as long as the `uuid` property and the optional `lambdaPurpose` property stay the same whenever they're declared into the
stack.

A typical use case of this function is when a higher level construct needs to declare a Lambda function as part of it but
needs to guarantee that the function is declared once. However, a user of this higher level construct can declare it any
number of times and with different properties. Using `SingletonFunction` here with a fixed `uuid` will guarantee this.

For example, the `LogRetention` construct requires only one single lambda function for all different log groups whose
retention it seeks to manage.

### Language-specific APIs
Language-specific higher level constructs are provided in separate modules:

Expand Down
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export interface SingletonFunctionProps extends FunctionProps {
/**
* A Lambda that will only ever be added to a stack once.
*
* The lambda is identified using the value of 'uuid'. Run 'uuidgen'
* for every SingletonLambda you create.
* This construct is a way to guarantee that the lambda function will be guaranteed to be part of the stack,
* once and only once, irrespective of how many times the construct is declared to be part of the stack.
* This is guaranteed as long as the `uuid` property and the optional `lambdaPurpose` property stay the same
* whenever they're declared into the stack.
*
* @resource AWS::Lambda::Function
*/
Expand Down