addEventSource method
Identifies a stream as an event source for an AWS Lambda function. It can be either an Amazon Kinesis stream or a Amazon DynamoDB stream. AWS Lambda invokes the specified function when records are posted to the stream.
This is the pull model, where AWS Lambda invokes the function. For more information, go to AWS Lambda: How it Works in the AWS Lambda Developer Guide.
This association between an Amazon Kinesis stream and an AWS Lambda function is called the event source mapping. You provide the configuration information (for example, which stream to read from and which AWS Lambda function to invoke) for the event source mapping in the request body.
Each event source, such as a Kinesis stream, can only be associated with one AWS Lambda function. If you call AddEventSource for an event source that is already mapped to another AWS Lambda function, the existing mapping is updated to call the new function instead of the old one.
This operation requires permission for the iam:PassRole
action for the IAM role. It also requires permission for the
lambda:AddEventSource
action.
May throw ServiceException. May throw InvalidParameterValueException.
Parameter eventSource
:
The Amazon Resource Name (ARN) of the Amazon Kinesis stream that is the
event source. Any record added to this stream causes AWS Lambda to invoke
your Lambda function. AWS Lambda POSTs the Amazon Kinesis event,
containing records, to your Lambda function as JSON.
Parameter functionName
:
The Lambda function to invoke when AWS Lambda detects an event on the
stream.
Parameter role
:
The ARN of the IAM role (invocation role) that AWS Lambda can assume to
read from the stream and invoke the function.
Parameter batchSize
:
The largest number of records that AWS Lambda will give to your function
in a single event. The default is 100 records.
Parameter parameters
:
A map (key-value pairs) defining the configuration for AWS Lambda to use
when reading the event source. Currently, AWS Lambda supports only the
InitialPositionInStream
key. The valid values are:
"TRIM_HORIZON" and "LATEST". The default value is "TRIM_HORIZON". For more
information, go to ShardIteratorType
in the Amazon Kinesis Service API Reference.
Implementation
Future<EventSourceConfiguration> addEventSource({
required String eventSource,
required String functionName,
required String role,
int? batchSize,
Map<String, String>? parameters,
}) async {
ArgumentError.checkNotNull(eventSource, 'eventSource');
ArgumentError.checkNotNull(functionName, 'functionName');
_s.validateStringLength(
'functionName',
functionName,
1,
64,
isRequired: true,
);
ArgumentError.checkNotNull(role, 'role');
final $payload = <String, dynamic>{
'EventSource': eventSource,
'FunctionName': functionName,
'Role': role,
if (batchSize != null) 'BatchSize': batchSize,
if (parameters != null) 'Parameters': parameters,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri: '/2014-11-13/event-source-mappings/',
exceptionFnMap: _exceptionFns,
);
return EventSourceConfiguration.fromJson(response);
}