create_event_source_mapping
¶
create_event_source_mapping(
function_name: NamespacedFunctionName,
*,
config_overrides: Optional[LambdaClientConfig] = None,
event_source_arn: Optional[Arn] = None,
enabled: Optional[Enabled] = None,
batch_size: Optional[BatchSize] = None,
filter_criteria: Optional[FilterCriteria] = None,
kms_key_arn: Optional[KMSKeyArn] = None,
metrics_config: Optional[EventSourceMappingMetricsConfig] = None,
logging_config: Optional[EventSourceMappingLoggingConfig] = None,
scaling_config: Optional[ScalingConfig] = None,
maximum_batching_window_in_seconds: Optional[MaximumBatchingWindowInSeconds] = None,
parallelization_factor: Optional[ParallelizationFactor] = None,
starting_position: Optional[EventSourcePosition] = None,
starting_position_timestamp: Optional[Date] = None,
destination_config: Optional[DestinationConfig] = None,
maximum_record_age_in_seconds: Optional[MaximumRecordAgeInSeconds] = None,
bisect_batch_on_function_error: Optional[BisectBatchOnFunctionError] = None,
maximum_retry_attempts: Optional[MaximumRetryAttemptsEventSourceMapping] = None,
tags: Optional[Tags] = None,
tumbling_window_in_seconds: Optional[TumblingWindowInSeconds] = None,
topics: Optional[Topics] = None,
queues: Optional[Queues] = None,
source_access_configurations: Optional[SourceAccessConfigurations] = None,
self_managed_event_source: Optional[SelfManagedEventSource] = None,
function_response_types: Optional[FunctionResponseTypeList] = None,
amazon_managed_kafka_event_source_config: Optional[
AmazonManagedKafkaEventSourceConfig
] = None,
self_managed_kafka_event_source_config: Optional[
SelfManagedKafkaEventSourceConfig
] = None,
document_db_event_source_config: Optional[DocumentDBEventSourceConfig] = None,
provisioned_poller_config: Optional[ProvisionedPollerConfig] = None,
) -> EventSourceMappingConfiguration
Creates a mapping between an event source and an Lambda Event Function. Lambda reads items from the event source and invokes the function.
For details about how to configure different event sources, see the following topics.
The following error handling options are available for stream sources (DynamoDB, Kinesis, Amazon MSK, and self-managed Apache Kafka):
-
BisectBatchOnFunctionError– If the function returns an error, split the batch in two and retry. -
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. -
OnFailure– Send discarded records to an Amazon SQS queue, Amazon SNS topic, Kafka topic, or Amazon S3 bucket. For more information, see Adding a destination.
The following option is available only for DynamoDB and Kinesis event sources:
-
ParallelizationFactor– Process multiple batches from each shard concurrently.
For information about which configuration parameters apply to each event source, see the following topics.
Parameters:
-
event_source_arn(Optional[Arn], default:None) –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 or the ARN of the VPC connection (for cross-account event source mappings).
-
Amazon MQ – The ARN of the broker.
-
Amazon DocumentDB – The ARN of the DocumentDB change stream.
-
-
function_name(NamespacedFunctionName) –The name or ARN 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.
The length constraint applies only to the full ARN. If you specify only the function name, it's limited to 64 characters in length.
-
-
enabled(Optional[Enabled], default:None) –When true, the event source mapping is active. When false, Lambda pauses polling and invocation.
Default: True
-
batch_size(Optional[BatchSize], default:None) –The maximum number of records in each batch that Lambda pulls from your stream or queue and sends to your function. Lambda passes all of the records in the batch to the function in a single call, up to the payload limit for synchronous invocation (6 MB).
-
Amazon Kinesis – Default 100. Max 10,000.
-
Amazon DynamoDB Streams – Default 100. Max 10,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.
-
Amazon MQ (ActiveMQ and RabbitMQ) – Default 100. Max 10,000.
-
DocumentDB – Default 100. Max 10,000.
-
-
filter_criteria(Optional[FilterCriteria], default:None) –An object that defines the filter criteria that determine whether Lambda should process an event. For more information, see Lambda event filtering.
-
kms_key_arn(Optional[KMSKeyArn], default:None) –The ARN of the Key Management Service (KMS) customer managed key that Lambda uses to encrypt your function's filter criteria. By default, Lambda does not encrypt your filter criteria object. Specify this property to encrypt data using your own customer managed key.
-
metrics_config(Optional[EventSourceMappingMetricsConfig], default:None) –The metrics configuration for your event source. For more information, see Event source mapping metrics.
-
logging_config(Optional[EventSourceMappingLoggingConfig], default:None) –(Amazon MSK, and self-managed Apache Kafka only) The logging configuration for your event source. For more information, see Event source mapping logging.
-
scaling_config(Optional[ScalingConfig], default:None) –(Amazon SQS only) The scaling configuration for the event source. For more information, see Configuring maximum concurrency for Amazon SQS event sources.
-
maximum_batching_window_in_seconds(Optional[MaximumBatchingWindowInSeconds], default:None) –The maximum amount of time, in seconds, that Lambda spends gathering records before invoking the function. You can configure
MaximumBatchingWindowInSecondsto any value from 0 seconds to 300 seconds in increments of seconds.For Kinesis, DynamoDB, and Amazon SQS event sources, the default batching window is 0 seconds. For Amazon MSK, Self-managed Apache Kafka, Amazon MQ, and DocumentDB event sources, the default batching window is 500 ms. Note that because you can only change
MaximumBatchingWindowInSecondsin increments of seconds, you cannot revert back to the 500 ms default batching window after you have changed it. To restore the default batching window, you must create a new event source mapping.Related setting: For Kinesis, DynamoDB, and Amazon SQS event sources, when you set
BatchSizeto a value greater than 10, you must setMaximumBatchingWindowInSecondsto at least 1. -
parallelization_factor(Optional[ParallelizationFactor], default:None) –(Kinesis and DynamoDB Streams only) The number of batches to process from each shard concurrently.
-
starting_position(Optional[EventSourcePosition], default:None) –The position in a stream from which to start reading. Required for Amazon Kinesis and Amazon DynamoDB Stream event sources.
AT_TIMESTAMPis supported only for Amazon Kinesis streams, Amazon DocumentDB, Amazon MSK, and self-managed Apache Kafka. -
starting_position_timestamp(Optional[Date], default:None) –With
StartingPositionset toAT_TIMESTAMP, the time from which to start reading.StartingPositionTimestampcannot be in the future. -
destination_config(Optional[DestinationConfig], default:None) –(Kinesis, DynamoDB Streams, Amazon MSK, and self-managed Apache Kafka) A configuration object that specifies the destination of an event after Lambda processes it.
-
maximum_record_age_in_seconds(Optional[MaximumRecordAgeInSeconds], default:None) –(Kinesis, DynamoDB Streams, Amazon MSK, and self-managed Apache Kafka) Discard records older than the specified age. The default value is infinite (-1).
-
bisect_batch_on_function_error(Optional[BisectBatchOnFunctionError], default:None) –(Kinesis, DynamoDB Streams, Amazon MSK, and self-managed Apache Kafka) If the function returns an error, split the batch in two and retry.
-
maximum_retry_attempts(Optional[MaximumRetryAttemptsEventSourceMapping], default:None) –(Kinesis, DynamoDB Streams, Amazon MSK, and self-managed Apache Kafka) 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.
-
tags(Optional[Tags], default:None) –A list of tags to apply to the event source mapping.
-
tumbling_window_in_seconds(Optional[TumblingWindowInSeconds], default:None) –(Kinesis and DynamoDB Streams only) The duration in seconds of a processing window for DynamoDB and Kinesis Streams event sources. A value of 0 seconds indicates no tumbling window.
-
topics(Optional[Topics], default:None) –The name of the Kafka topic.
-
queues(Optional[Queues], default:None) –(MQ) The name of the Amazon MQ broker destination queue to consume.
-
source_access_configurations(Optional[SourceAccessConfigurations], default:None) –An array of authentication protocols or VPC components required to secure your event source.
-
self_managed_event_source(Optional[SelfManagedEventSource], default:None) –The self-managed Apache Kafka cluster to receive records from.
-
function_response_types(Optional[FunctionResponseTypeList], default:None) –(Kinesis, DynamoDB Streams, Amazon MSK, self-managed Apache Kafka, and Amazon SQS) A list of current response type enums applied to the event source mapping.
-
amazon_managed_kafka_event_source_config(Optional[AmazonManagedKafkaEventSourceConfig], default:None) –Specific configuration settings for an Amazon Managed Streaming for Apache Kafka (Amazon MSK) event source.
-
self_managed_kafka_event_source_config(Optional[SelfManagedKafkaEventSourceConfig], default:None) –Specific configuration settings for a self-managed Apache Kafka event source.
-
document_db_event_source_config(Optional[DocumentDBEventSourceConfig], default:None) –Specific configuration settings for a DocumentDB event source.
-
provisioned_poller_config(Optional[ProvisionedPollerConfig], default:None) –(Amazon SQS, Amazon MSK, and self-managed Apache Kafka only) The provisioned mode configuration for the event source. For more information, see provisioned mode.
Raises:
-
InvalidParameterValueException–One of the parameters in the request is not valid.
-
ResourceConflictException–The resource already exists, or another operation is in progress.
-
ResourceNotFoundException–The resource specified in the request does not exist.
-
ServiceException–The Lambda service encountered an internal error.
-
TooManyRequestsException–The request throughput limit was exceeded. For more information, see Lambda quotas.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create a mapping between an event source and an AWS Lambda function The following example creates a mapping between an SQS queue and the my-function Lambda function.
>>> client.create_event_source_mapping(batch_size=5, event_source_arn='arn:aws:sqs:us-west-2:123456789012:my-queue', function_name='my-function')
Source code in docs_src/capo_lambda/_services/_lambda.py
2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 | |