import type { Construct } from "constructs"; import type { EventBatch, IEventSource } from "./event-source"; import type { Function, FunctionProps } from "./function"; export declare type Processor = (item: Item, record: Record, event: Event, raw: Raw) => Processed | Promise; export declare type BatchProcessor = (batch: Element[], event: Event, raw: Raw) => Promise; /** * The {@link IIterable} interface provides utility functions for working with streams of data. * * @typeParam Item the type of items in this Iterable. * @typeParam RawEvent the type of the Event payload received in the Lambda Invocation. * @typeParam ParsedEvent the parsed Event payload containing pre-processed Records of type ParsedRecord. * @typeParam ParsedRecord the type of the Record in the ParsedEvent * @typeParam Response the type of the Response payload expected by the Event Source that invoked the Lambda Function. * @typeParam EventSourceConfig the properties for configuring the Event Source attached to the Lambda Function. * @see {@link Queue} */ export interface IIterable { /** * Map over each {@link Item} and apply a transformation function. * * ```ts * // transformations can be synchronous * it.map((item: string) => item.length) * .forEach((item: number) => ..) * * // transformations can also be asynchronous * it.map(async (item: string) => client.getCount(item)); * .forEach((item: number) => ..) * ``` * * @param callbackfn function to apply to each {@link Item}. */ map(callbackfn: Processor): IIterable; /** * Calls a defined callback function on each element of an array. Then, flattens * the result into a new array. * * ```ts * // transformations can be synchronous * it.flatMap((item: string) => [item.length]) * .forEach((item: number) => ..) * * // transformations can also be asynchronous * it.flatMap(async (item: string) => [client.getCount(item)]); * .forEach((item: number) => ..) * ``` * * @param callbackfn The flatMap method calls the callback function one time for each element in the array. */ flatMap(callbackfn: Processor): IIterable; /** * Returns the elements that meet the condition specified in a callback function. * * ```ts * // filters can be synchronous * it.filter(item => item.length > 0) * * // filters can call asynchronous code, such as an API client * it.filter(async item => client.get()) * ``` * * @param predicate The filter method calls the predicate function one time for each element in {@link Iterable} and returns a new {@link Iterable} containing only those elements where the {@link predicate} returns `true`. * {@label with_narrowing} */ filter(predicate: (item: Item, record: ParsedRecord, event: ParsedEvent, raw: RawEvent) => item is U): IIterable; /** * Returns the elements that meet the condition specified in a callback function. * * ```ts * // filters can be synchronous * it.filter(item => item.length > 0) * * // filters can call asynchronous code, such as an API client * it.filter(async item => client.get()) * ``` * * @param predicate The filter method calls the predicate function one time for each element in {@link Iterable} and returns a new {@link Iterable} containing only those elements where the {@link predicate} returns `true`. * * {@label without_narrowing} */ filter(predicate: Processor): IIterable; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param id ID of the created Lambda {@link Function} Construct added as a child of the underlying Resource, e.g. {@link Queue}. * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(id: string, props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * @param scope Construct to use as the parent of the created Lambda {@link Function}. * @param id ID of the created Lambda {@link Function} Construct added as a child of the {@link scope} * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(scope: Construct, id: string, props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param id ID of the created Lambda {@link Function} Construct added as a child of the underlying resource, e.g. a SQS {@link Queue}. * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(id: string, props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param scope Construct to use as the parent of the created Lambda {@link Function}. * @param id ID of the created Lambda {@link Function} Construct added as a child of the {@link scope} * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(scope: Construct, id: string, props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; } export declare function isIterable(a: any): a is Iterable; /** * @typeParam Item the type of items in this Iterable. * @typeParam RawEvent the type of the Event payload received in the Lambda Invocation. * @typeParam ParsedEvent the parsed Event payload containing pre-processed Records of type ParsedRecord. * @typeParam ParsedRecord the type of the Record in the ParsedEvent * @typeParam Response the type of the Response payload expected by the Event Source that invoked the Lambda Function. * @typeParam EventSourceConfig the properties for configuring the Event Source attached to the Lambda Function. */ export declare class Iterable implements Iterable { private readonly prev; private readonly callbackfn; /** * Properties that are required to be specified on the EventSourceConfig. */ private readonly requiredEventSourceConfig; /** * @hidden */ readonly kind = "Iterable"; constructor(prev: IEventSource | Iterable, callbackfn: Processor, /** * Properties that are required to be specified on the EventSourceConfig. */ requiredEventSourceConfig: Partial); /** * Map over each {@link Item} and apply a transformation function. * * ```ts * // transformations can be synchronous * it.map((item: string) => item.length) * .forEach((item: number) => ..) * * // transformations can also be asynchronous * it.map(async (item: string) => client.getCount(item)); * .forEach((item: number) => ..) * ``` * * @param callbackfn function to apply to each {@link Item}. */ map(callbackfn: Processor): Iterable; /** * Calls a defined callback function on each element of an array. Then, flattens * the result into a new array. * * ```ts * // transformations can be synchronous * it.flatMap((item: string) => [item.length]) * .forEach((item: number) => ..) * * // transformations can also be asynchronous * it.flatMap(async (item: string) => [client.getCount(item)]); * .forEach((item: number) => ..) * ``` * * @param callbackfn The flatMap method calls the callback function one time for each element in the array. */ flatMap(callbackfn: Processor): Iterable; /** * Returns the elements that meet the condition specified in a callback function. * * ```ts * // filters can be synchronous * it.filter(item => item.length > 0) * * // filters can call asynchronous code, such as an API client * it.filter(async item => client.get()) * ``` * * @param predicate The filter method calls the predicate function one time for each element in {@link Iterable} and returns a new {@link Iterable} containing only those elements where the {@link predicate} returns `true`. */ filter(predicate: (item: Item, record: ParsedRecord, event: ParsedEvent, raw: RawEvent) => item is U): Iterable; /** * Returns the elements that meet the condition specified in a callback function. * * ```ts * // filters can be synchronous * it.filter(item => item.length > 0) * * // filters can call asynchronous code, such as an API client * it.filter(async item => client.get()) * ``` * * @param predicate The filter method calls the predicate function one time for each element in {@link Iterable} and returns a new {@link Iterable} containing only those elements where the {@link predicate} returns `true`. */ filter(predicate: Processor): Iterable; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * * @param id ID of the created Lambda {@link Function} Construct added as a child of the underlying Resource, e.g. {@link Queue}. * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(id: string, props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for each element in an {@link Iterable}, for example * if receiving 10 messages from SQS, the {@link callbackfn} function will be called * once for each message. * * Calling `forEach` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEach(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEach({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEach` methods. * ```ts * // specify just the `id` * queue.messages().forEach("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEach(this, "id", props, callback); * ``` * @param scope Construct to use as the parent of the created Lambda {@link Function}. * @param id ID of the created Lambda {@link Function} Construct added as a child of the {@link scope} * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEach(scope: Construct, id: string, props: FunctionProps & EventSourceConfig, callbackfn: Processor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param id ID of the created Lambda {@link Function} Construct added as a child of the underlying resource, e.g. a SQS {@link Queue}. * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(id: string, props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; /** * Performs the specified action for all of the elements in an {@link Iterable}. Calling * `forEachBatch` will create a new Lambda {@link Function} and attach the corresponding * Event Source, for example a SQS {@link Queue} Polling Event Source. * * The {@link callbackfn} will be called once with an array of all elements in the current * batch of events received from the Event Source, for example all of the messages polled * from a SQS {@link Queue}. * * #### Example Usage for a SQS {@link Queue} * * ```ts * const myTable = new Table(scope, "table", { .. }); * const queue = new Queue(scope, "queue"); * * queue.messages().forEachBatch(async (message) => { * // put each message from the Queue into a Table * await $AWS.DynamoDB.PutItem({ * Table: myTable, * Item: { * id: { S: message.id }, * message: { S: JSON.stringify(message) } * } * }) * }); * ``` * * #### Lambda Function Configuration * The {@link Function}'s `props`, for example `memorySize` or `timeout` can be configured with * the `props` argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * memorySize: 256, * timeout: Duration.minutes(1) * }, handler); * ``` * * #### Event Source Configuration * * The EventSource's `props`, for example `batchSize`, can also be configured with the `props` * argument: * ```ts * import { Duration } from "aws-cdk-lib"; * * queue.messages().forEachBatch({ * batchSize: 10 * }, handler); * ``` * * #### Override `scope` and `id` * * The `scope` of the Function defaults to the Resource underlying this {@link Iterable} and * and the `id` defaults to `"onEvent"`. To override `scope` and `id`, you can use one of the * overloaded `forEachBatch` methods. * ```ts * // specify just the `id` * queue.messages().forEachBatch("id", props, callbackfn) * * // specify both the `scope` and `id`: * queue.messages().forEachBatch(this, "id", props, callback); * ``` * @param scope Construct to use as the parent of the created Lambda {@link Function}. * @param id ID of the created Lambda {@link Function} Construct added as a child of the {@link scope} * @param props configuration properties for the Lambda {@link Function} and corresponding Event Source. * @param callbackfn forEach calls the callbackfn function one time for each element in the array. */ forEachBatch(scope: Construct, id: string, props: FunctionProps & EventSourceConfig, callbackfn: BatchProcessor): Function; /** * @hidden */ private getCallChain; /** * @hidden */ private getSource; } //# sourceMappingURL=iterable.d.ts.map