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

MAPSAPI-2426: Allow stream lambdas to have FilterCriteria defined #147

Merged
merged 12 commits into from
Mar 27, 2024
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.1.0

- Allow `FilterCriteria` property to be defined for Lambda shortcuts

## 8.0.0

- Updates `cf.shortcuts.ScheduledLambda` to use EventBridge Scheduler instead of EventBridge Rules to schedule lambda invocations. When using this version your template will have the following changes per scheduled lambda instance,
Expand Down
1 change: 1 addition & 0 deletions lib/shortcuts/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.
| [options.DeadLetterConfig] | <code>Object</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-deadletterconfig). |
| [options.Description] | <code>String</code> | <code>&#x27;${logical name} in the ${stack name} stack&#x27;</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-description). |
| [options.Environment] | <code>Object</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-environment). |
| [options.FilterCriteria] | <code>Object</code> | | See [AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html) |
| [options.FunctionName] | <code>String</code> | <code>&#x27;${stack name}-${logical name}&#x27;</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionname). |
| [options.Handler] | <code>String</code> | <code>&#x27;index.handler&#x27;</code> | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-handler). |
| [options.KmsKeyArn] | <code>String</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-kmskeyarn). |
Expand Down
8 changes: 7 additions & 1 deletion lib/shortcuts/stream-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Lambda = require('./lambda');
* @param {Number} [options.MaximumBatchingWindowInSeconds=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds).
* @param {Boolean} [options.Enabled=true] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled).
* @param {String} [options.StartingPosition='LATEST'] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition).
* @param {Object} [options.FilterCriteria] - See [AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html).
*
* @example
* const cf = require('@mapbox/cloudfriend');
branyip marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -40,7 +41,8 @@ class StreamLambda extends Lambda {
BatchSize = 1,
MaximumBatchingWindowInSeconds,
Enabled = true,
StartingPosition = 'LATEST'
StartingPosition = 'LATEST',
FilterCriteria = undefined
} = options;

const required = [EventSourceArn];
Expand All @@ -60,6 +62,10 @@ class StreamLambda extends Lambda {
}
};

if (FilterCriteria) {
this.Resources[`${this.LogicalName}EventSource`].Properties.FilterCriteria = FilterCriteria;
}
branyip marked this conversation as resolved.
Show resolved Hide resolved

const generatedRoleRef = this.Resources[`${this.LogicalName}Role`];
const streamStatement = {
Effect: 'Allow',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/cloudfriend",
"version": "8.0.0",
"version": "8.1.0-dev",
"description": "Helper functions for assembling CloudFormation templates in JavaScript",
"main": "index.js",
"engines": {
Expand Down
Loading