createEventSourceMapping method
- required String functionName,
- int? batchSize,
- bool? bisectBatchOnFunctionError,
- DestinationConfig? destinationConfig,
- bool? enabled,
- String? eventSourceArn,
- List<
FunctionResponseType> ? functionResponseTypes, - int? maximumBatchingWindowInSeconds,
- int? maximumRecordAgeInSeconds,
- int? maximumRetryAttempts,
- int? parallelizationFactor,
- List<
String> ? queues, - SelfManagedEventSource? selfManagedEventSource,
- List<
SourceAccessConfiguration> ? sourceAccessConfigurations, - EventSourcePosition? startingPosition,
- DateTime? startingPositionTimestamp,
- List<
String> ? topics, - int? tumblingWindowInSeconds,
Creates a mapping between an event source and an AWS Lambda function. Lambda reads items from the event source and triggers the function.
For details about each event source type, see the following topics.
- Using AWS Lambda with Amazon DynamoDB
- Using AWS Lambda with Amazon Kinesis
- Using AWS Lambda with Amazon SQS
- Using AWS Lambda with Amazon MQ
- Using AWS Lambda with Amazon MSK
- Using AWS Lambda with Self-Managed Apache Kafka
-
BisectBatchOnFunctionError
- If the function returns an error, split the batch in two and retry. -
DestinationConfig
- Send discarded records to an Amazon SQS queue or Amazon SNS topic. -
MaximumRecordAgeInSeconds
- Discard records older than the specified age. The default value is infinite (-1). When set to infinite (-1), failed records are retried until the record expires -
MaximumRetryAttempts
- Discard records after the specified number of retries. The default value is infinite (-1). When set to infinite (-1), failed records are retried until the record expires. -
ParallelizationFactor
- Process multiple batches from each shard concurrently.
May throw ServiceException. May throw InvalidParameterValueException. May throw ResourceConflictException. May throw TooManyRequestsException. May throw ResourceNotFoundException.
Parameter functionName
:
The name of the Lambda function.
Name formats
-
Function name -
MyFunction
. -
Function ARN -
arn:aws:lambda:us-west-2:123456789012:function:MyFunction
. -
Version or Alias ARN -
arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD
. -
Partial ARN -
123456789012:function:MyFunction
.
Parameter batchSize
:
The maximum number of items to retrieve in a single batch.
- Amazon Kinesis - Default 100. Max 10,000.
- Amazon DynamoDB Streams - Default 100. Max 1,000.
- Amazon Simple Queue Service - Default 10. For standard queues the max is 10,000. For FIFO queues the max is 10.
- Amazon Managed Streaming for Apache Kafka - Default 100. Max 10,000.
- Self-Managed Apache Kafka - Default 100. Max 10,000.
Parameter bisectBatchOnFunctionError
:
(Streams) If the function returns an error, split the batch in two and
retry.
Parameter destinationConfig
:
(Streams) An Amazon SQS queue or Amazon SNS topic destination for
discarded records.
Parameter enabled
:
If true, the event source mapping is active. Set to false to pause polling
and invocation.
Parameter eventSourceArn
:
The Amazon Resource Name (ARN) of the event source.
- Amazon Kinesis - The ARN of the data stream or a stream consumer.
- Amazon DynamoDB Streams - The ARN of the stream.
- Amazon Simple Queue Service - The ARN of the queue.
- Amazon Managed Streaming for Apache Kafka - The ARN of the cluster.
Parameter functionResponseTypes
:
(Streams) A list of current response type enums applied to the event
source mapping.
Parameter maximumBatchingWindowInSeconds
:
(Streams and SQS standard queues) The maximum amount of time to gather
records before invoking the function, in seconds.
Parameter maximumRecordAgeInSeconds
:
(Streams) Discard records older than the specified age. The default value
is infinite (-1).
Parameter maximumRetryAttempts
:
(Streams) Discard records after the specified number of retries. The
default value is infinite (-1). When set to infinite (-1), failed records
will be retried until the record expires.
Parameter parallelizationFactor
:
(Streams) The number of batches to process from each shard concurrently.
Parameter queues
:
(MQ) The name of the Amazon MQ broker destination queue to consume.
Parameter selfManagedEventSource
:
The Self-Managed Apache Kafka cluster to send records.
Parameter sourceAccessConfigurations
:
An array of the authentication protocol, or the VPC components to secure
your event source.
Parameter startingPosition
:
The position in a stream from which to start reading. Required for Amazon
Kinesis, Amazon DynamoDB, and Amazon MSK Streams sources.
AT_TIMESTAMP
is only supported for Amazon Kinesis streams.
Parameter startingPositionTimestamp
:
With StartingPosition
set to AT_TIMESTAMP
, the
time from which to start reading.
Parameter topics
:
The name of the Kafka topic.
Parameter tumblingWindowInSeconds
:
(Streams) The duration of a processing window in seconds. The range is
between 1 second up to 15 minutes.
Implementation
Future<EventSourceMappingConfiguration> createEventSourceMapping({
required String functionName,
int? batchSize,
bool? bisectBatchOnFunctionError,
DestinationConfig? destinationConfig,
bool? enabled,
String? eventSourceArn,
List<FunctionResponseType>? functionResponseTypes,
int? maximumBatchingWindowInSeconds,
int? maximumRecordAgeInSeconds,
int? maximumRetryAttempts,
int? parallelizationFactor,
List<String>? queues,
SelfManagedEventSource? selfManagedEventSource,
List<SourceAccessConfiguration>? sourceAccessConfigurations,
EventSourcePosition? startingPosition,
DateTime? startingPositionTimestamp,
List<String>? topics,
int? tumblingWindowInSeconds,
}) async {
ArgumentError.checkNotNull(functionName, 'functionName');
_s.validateStringLength(
'functionName',
functionName,
1,
140,
isRequired: true,
);
_s.validateNumRange(
'batchSize',
batchSize,
1,
10000,
);
_s.validateNumRange(
'maximumBatchingWindowInSeconds',
maximumBatchingWindowInSeconds,
0,
300,
);
_s.validateNumRange(
'maximumRecordAgeInSeconds',
maximumRecordAgeInSeconds,
-1,
604800,
);
_s.validateNumRange(
'maximumRetryAttempts',
maximumRetryAttempts,
-1,
10000,
);
_s.validateNumRange(
'parallelizationFactor',
parallelizationFactor,
1,
10,
);
_s.validateNumRange(
'tumblingWindowInSeconds',
tumblingWindowInSeconds,
0,
900,
);
final $payload = <String, dynamic>{
'FunctionName': functionName,
if (batchSize != null) 'BatchSize': batchSize,
if (bisectBatchOnFunctionError != null)
'BisectBatchOnFunctionError': bisectBatchOnFunctionError,
if (destinationConfig != null) 'DestinationConfig': destinationConfig,
if (enabled != null) 'Enabled': enabled,
if (eventSourceArn != null) 'EventSourceArn': eventSourceArn,
if (functionResponseTypes != null)
'FunctionResponseTypes':
functionResponseTypes.map((e) => e.toValue()).toList(),
if (maximumBatchingWindowInSeconds != null)
'MaximumBatchingWindowInSeconds': maximumBatchingWindowInSeconds,
if (maximumRecordAgeInSeconds != null)
'MaximumRecordAgeInSeconds': maximumRecordAgeInSeconds,
if (maximumRetryAttempts != null)
'MaximumRetryAttempts': maximumRetryAttempts,
if (parallelizationFactor != null)
'ParallelizationFactor': parallelizationFactor,
if (queues != null) 'Queues': queues,
if (selfManagedEventSource != null)
'SelfManagedEventSource': selfManagedEventSource,
if (sourceAccessConfigurations != null)
'SourceAccessConfigurations': sourceAccessConfigurations,
if (startingPosition != null)
'StartingPosition': startingPosition.toValue(),
if (startingPositionTimestamp != null)
'StartingPositionTimestamp':
unixTimestampToJson(startingPositionTimestamp),
if (topics != null) 'Topics': topics,
if (tumblingWindowInSeconds != null)
'TumblingWindowInSeconds': tumblingWindowInSeconds,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri: '/2015-03-31/event-source-mappings/',
exceptionFnMap: _exceptionFns,
);
return EventSourceMappingConfiguration.fromJson(response);
}